Hello,
I just stumbled upon behavior that seems to "fail silently" regardless of
its very questionable validity:
<?php
$a = 1;
var_dump($a[123]); // NULL, no notice
Are there specific reasons why no notice is thrown? Is it by design? If so,
does anyone remember why?
I haven't checked if this affects other types too. I know that an
assignment to an array key of a non-array would cause a cast of the value
to array
, but a mere read operation should surely cause a notice to be
raised in the above scenario.
Cheers,
Marco Pivetta
Hello Marco,
Actually, you are trying to access to something that does not exist, so
you get a null value. This part is logical. However, yes, a notice would
be welcomed except it may be skipped for historical reasons I reckon.
Probably to work well with isset
or similar scenario.
Cheers.
Hello,
I just stumbled upon behavior that seems to "fail silently" regardless of
its very questionable validity:<?php
$a = 1;
var_dump($a[123]); // NULL, no notice
Are there specific reasons why no notice is thrown? Is it by design? If so,
does anyone remember why?I haven't checked if this affects other types too. I know that an
assignment to an array key of a non-array would cause a cast of the value
toarray
, but a mere read operation should surely cause a notice to be
raised in the above scenario.Cheers,
Marco Pivetta
I just stumbled upon behavior that seems to "fail silently" regardless of
its very questionable validity:<?php
$a = 1;
var_dump($a[123]); // NULL, no notice
Are there specific reasons why no notice is thrown? Is it by design? If so,
does anyone remember why?I haven't checked if this affects other types too. I know that an
assignment to an array key of a non-array would cause a cast of the value
toarray
, but a mere read operation should surely cause a notice to be
raised in the above scenario.
For the record: there are several bug reports/feature requests regarding
this issue, e.g. https://bugs.php.net/bug.php?id=37676.
--
Christoph M. Becker