3

The isset() documentation clearly tells me that

isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.


So, echo (isset(null)) ? 'YES' : 'NO'; is giving the fatal error as excepted;

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)


Question;

Why does isset(null['?']) does not trow the same error;

echo (isset(null['?'])) ? 'YES' : 'NO';

NO


I'm expecting the same error, since isset() can't be used on non-variables.

I'm aware that

<?php

$x = NULL;
$x['?'] = 'hi';
echo gettype($x); // array

will set $x to an array, however, (as expected) echo @gettype(null['1']); stays null?

0stone0
  • 34,288
  • 4
  • 39
  • 64
  • I understand why my question is voted as [duplicate], however, those questions are 6-7 years old, without any solids answers, and there is not much over PHP7.4. [One comment](https://wiki.php.net/rfc/notice-for-non-valid-array-container) says that it should throw a notice, but it's not? Any – 0stone0 Mar 31 '20 at 14:39
  • This is fine - think of the compiler - you are passing `null` to `isset` than after null is created on the stack its mutated to an array with a key '?' which points to null. so at the end its exactly as `isset(["?" => null]["?"]) // FALSE` – Shlomi Hassid Sep 15 '21 at 12:18

0 Answers0