1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 02:33:17 +02:00
Files
archived-php-src/Zend/tests/dereference_010.phpt
T
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

34 lines
532 B
PHP

--TEST--
Testing dereference in non-array values
--FILE--
<?php
error_reporting(E_ALL);
function a() {
return 1;
}
$a = 1;
var_dump($a[1]);
var_dump(a()[1]);
function b() {
return new stdClass;
}
var_dump(b()[1]);
?>
--EXPECTF--
Notice: Trying to access array offset on value of type int in %s on line %d
NULL
Notice: Trying to access array offset on value of type int in %s on line %d
NULL
Fatal error: Uncaught Error: Cannot use object of type stdClass as array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d