So, although I don't know why PHP does this, I looked at the Zend code and at least tell you where you can find out exactly how PHP does it.
So, the important code in zend_fetch_dimension_address .
So, consider the above cases:
If this is IS_ARRAY - everything is obvious.
If it IS_OBJECT throws an error, if it does not have ArrayAccess .
If it IS_STRING will give an error if the length of the lines is not equal to zero.
If it is IS_NULL creates a new array.
If it IS_BOOL throws an error, if it is not false.
Otherwise, print an error.
So this confirms your and my tests:
Error if the object, non-empty string, true and other scalars, i.e. long and double. There is no error if the array, empty string, null and false . Thus, basically it does an automatic cast of most (but not all) false values.
NikiC source share