.. _classes-uselessnullsafeoperator: .. _useless-nullsafe-operator: Useless NullSafe Operator +++++++++++++++++++++++++ Nullsafe operator ``?->`` has no object when the types are never null, or when coalesce is active. The nullsafe operator protects the execution from accessing a method or a property on a null value. If the object part of the syntax cannot be null, then the nullsafe operator ``?->`` will not protect it. The nullsafe operator is filling the same duty as ``??`` operator, although with a more granular precision. .. code-block:: php methodOnA(); // goo() may return NULL: ?-> and ?? are filling the same duty goo()?->methodOnA ?? C; function goo() : ?A {} ?> Suggestions ___________ * Replace the null safe operator with the normal one. * Add the type null to the type declaration. * Check for null-coalesce operator ?? and choose the most appropriate. Specs _____ +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/UselessNullSafeOperator | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Changed Behavior `, :ref:`Class Review ` | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 2.6.5 | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Features | nullsafe-operator | +--------------+--------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+--------------------------------------------------------------------------------------------------------------------------+