Coalesce And The Fatal Error¶
The coalesce operator is based on the isset() feature of PHP. As such, it is prone to the same issues. This is the case with a sneaky fatal error.
Usually, coalesce hide any existence check on the left operand: that way, the default value may be used without a noisy warning. This does not apply when trying to check an array index on an object: it actually yields a fatal error.
Such situation is usually rare, as the structure of the variable is usually known to some extend. On the other hand, using ?? on the result of an unstructured dataset, such as from a JSON or YAML (or else), it becomes far more hazardous.
Note that json_decode() has an option to generate an object or an array. In such situation, it is safer to generate an array, which does not yield fatal errors. It might also be faster to run.