1.2.1332. Use NullSafe Operator

The nullsafe operator ?-> is an alternative to the object operator ->. It silently fails the whole expression if a null is used for object.

<?php

$o = null;

// PHP 8.0 Failsafe : $r = null;
$r = $o->method();

// PHP 7.4- : Call to a member function method() on null
$r = $o->method();

?>

See also PHP RFC: Nullsafe operator.

1.2.1332.1. Specs

Short name

Php/UseNullSafeOperator

Rulesets

All, Appinfo, CE, Changed Behavior, One Liners

Exakat since

2.1.6

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

object-operator

Available in

Entreprise Edition, Community Edition, Exakat Cloud