Array And Object Syntax, Not The Same Error¶
<?php
function foo() {
yield 1;
yield 2;
yield 3;
return ' 4';
}
function goo($a, $b, $c) {
print "$a $b $c";
}
print PHP_EOL;
goo(...foo());
goo(...($g = foo()));
echo $g->getReturn();
?>
When accessing an array as an object, PHP raises a Warning and continues with NULL.
When accessing an object as an array, without ArrayAccess, PHP raises a Fatal Error and stops.
It is critical to check the syntax used to access an object.
See Also¶
PHP Features¶
Last updated: 14 July 2026