Null Safe Object Operator

The Null Safe Object Operator behaves like the object operator, until the object is null. Then, instead of failing with a fatal error, it returns null.

<?php

function foo() : ?A {}

class A {
    public $property = 1;
}

// This will not fail, but also display nothing
echo foo()?->property;

// This will fail, when foo() returns null
echo foo()->property;

?>

Documentation

See also This nullsafe operator could come in PHP 8, Mastering Null Safety in PHP 8: A Comprehensive Guide to Using the Null Safe Operator, An Introduction to PHP 8.0’s Null Safe Operator, Null safe operator in practice, Exploring the Null Safe Operator in PHP

Related : Object Operator ->, Scope Resolution Operator ::

Added in PHP 8.0+