.. _classes-checkafternullsafeoperator: .. _check-after-null-safe-operator: Check After Null Safe Operator ++++++++++++++++++++++++++++++ Null-safe operator is ``?->``, which prevents fatal errors in case the object of the call is `NULL `_. The execution continues, though the `result `_ of the expression is now `NULL `_ too. While it saves some checks in certain cases, the null-safe operator should be followed by a check on the returned value to process any misfire of the method. This analysis checks that the `result `_ of the expression is collected, and compared to null. .. code-block:: php foo(); if ($result === null) { throw new ObjectException(The object could not call $foo\n); } ?> Connex PHP features ------------------- + `nullsafe-object-operator `_ Suggestions ___________ * Collect and check the result of the expression to null * Remove the null-safe operator and check before calling the object's method or property Specs _____ +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/CheckAfterNullSafeOperator | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior `, :ref:`Suggestions ` | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 2.6.4 | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | With PHP 8.1 and more recent | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Major | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+