mirror of
https://github.com/php/php-src.git
synced 2026-04-28 02:33:17 +02:00
c42b7dd6d3
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
34 lines
532 B
PHP
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
|