Yasuo Ohgaki wrote on 09/06/2015 11:44:
  $v = NULL;
  $v[0][1][2][3][4][5][6][7][8][9]; // NULL

this code is semantically wrong and I would like to have error/exception
for such
erroneous codes.

PHP considers an uninitialised variable to have the value NULL, and a NULL value to be coercable to any type, so this breaks down (logically, not necessarily literally) as follows:

- coerce $v to array()
- instantiate $v[0] as NULL
- coerce $v[0] to array()
- instantiate $v[0][1] as NULL
- and so on...

Raising a notice whenever the type is coerced would be inconsistent with other coercions (e.g. $foo = null; echo $foo + 1;). Raising a notice whenever the coerced array is actually accessed would result in a notice for every dimension, which would be very noisy.

Ideally, it would give a single notice, as in the below, but I'm not sure how that would be implemented:

 $v = array();
 var_dump($v[0][1][2][3][4][5][6][7][8][9]);
 // Notice: Undefined index: 0
 // NULL

Note that this is all rather different from the original case, which was about values which *cannot be coerced to array*.

Regards,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to