1
0
mirror of https://github.com/php/php-src.git synced 2026-04-10 17:43:13 +02:00
Files
archived-php-src/Zend/tests/024.phpt
Nikita Popov c42b7dd6d3 Throw notice on array access on illegal type
No notice is thrown for list() accesses, because we did not come
to an agreement regarding patterns like

    while ([$key, $value] = yield $it->next()) { ... }

where silent null access may be desirable.

No effort is made to suppress multiple notices in access chains
likes $x[0][0][0], because the technical complexity this causes
does not seem worthwhile.

RFC: https://wiki.php.net/rfc/notice-for-non-valid-array-container
2019-07-10 12:02:14 +02:00

58 lines
1.2 KiB
PHP

--TEST--
Testing operations with undefined variable
--FILE--
<?php
var_dump($a[1]);
var_dump($a[$c]);
var_dump($a + 1);
var_dump($a + $b);
var_dump($a++);
var_dump(++$b);
var_dump($a->$b);
var_dump($a->$b);
var_dump($a->$b->{$c[1]});
?>
--EXPECTF--
Notice: Undefined variable: a in %s on line %d
Notice: Trying to access array offset on value of type null in %s on line %d
NULL
Notice: Undefined variable: a in %s on line %d
Notice: Undefined variable: c in %s on line %d
Notice: Trying to access array offset on value of type null in %s on line %d
NULL
Notice: Undefined variable: a in %s on line %d
int(1)
Notice: Undefined variable: a in %s on line %d
Notice: Undefined variable: b in %s on line %d
int(0)
Notice: Undefined variable: a in %s on line %d
NULL
Notice: Undefined variable: b in %s on line %d
int(1)
Notice: Trying to get property '1' of non-object in %s on line %d
NULL
Notice: Trying to get property '1' of non-object in %s on line %d
NULL
Notice: Undefined variable: c in %s on line %d
Notice: Trying to access array offset on value of type null in %s on line %d
Notice: Trying to get property '1' of non-object in %s on line %d
Notice: Trying to get property '' of non-object in %s on line %d
NULL