Why does PHP not complain when I treat a null value as an array like this?

后端 未结 3 1662
你的背包
你的背包 2020-12-01 10:11

In PHP, I have error_reporting set to report everything including notices.

Why does the following not throw any notices, errors or anything else?

$my         


        
3条回答
  •  一整个雨季
    2020-12-01 11:09

    There are three types which it might be valid to use the array derefence syntax on:

    • Arrays
    • Strings (to access the character at the given position)
    • Object (objects implementing the ArrayAccess interface)

    For all other types, PHP just returns the undefined variable.

    Array dereference is handled by the FETCH_DIM_R opcode, which uses zend_fetch_dimension_address_read() to fetch the element.

    As you can see, there is a special case for NULLs, and a default case, both returning the undefined variable.

提交回复
热议问题