Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ext/spl/ArrayObjectBuiltin.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ public function execute(Frame $frame): void
0,
'iteratorClass'
);
if (null === $frame->returnVar) {
return;
}
$entry = VmReflection::resolveClassEntry($frame->vmContext, $iteratorClass);
if (null === $entry
|| !InterfaceCheck::entryIsInstanceOf($entry, ArrayIteratorBuiltin::CLASS_LC, $frame->vmContext)) {
Expand Down
36 changes: 35 additions & 1 deletion lib/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12778,7 +12778,41 @@ private function precedingInlineCallArgProducersBeforeCfgOp(array $cfgChildren,
array_unshift($producers, $child);
}

return $producers;
return $this->filterDeadVoidStatementMethodCallProducers($producers);
}

/**
* Drop void statement MethodCalls before a sibling MethodCall inline call-arg (#10778).
*
* php-cfg: `$ao->setIteratorClass('X'); echo var_export($ao->getIteratorClass(), true);`
* hoists both MethodCalls; the void setter must not map to var_export arg 0.
*
* @param list<Op\Expr> $producers
*
* @return list<Op\Expr>
*/
private function filterDeadVoidStatementMethodCallProducers(array $producers): array
{
if (\count($producers) < 2) {
return $producers;
}
$filtered = [];
$count = \count($producers);
for ($i = 0; $i < $count; ++$i) {
$producer = $producers[$i];
if (
$producer instanceof Op\Expr\MethodCall
&& property_exists($producer, 'result')
&& empty($producer->result->usages)
&& $i + 1 < $count
&& $producers[$i + 1] instanceof Op\Expr\MethodCall
) {
continue;
}
$filtered[] = $producer;
}

return $filtered;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
stdlib ArrayObject::getIteratorClass() after void setIteratorClass() in var_export expr (#10778, ext/spl/spl_array.c)
--FILE--
<?php
declare(strict_types=1);
$ao = new ArrayObject([1, 2, 3]);
$ao->setIteratorClass('ArrayIterator');
echo var_export($ao->getIteratorClass(), true), "\n";
if ('ArrayIterator' !== $ao->getIteratorClass()) {
exit(1);
}
?>
--EXPECT--
'ArrayIterator'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
$ao = new ArrayObject([1, 2, 3]);
$ao->setIteratorClass('ArrayIterator');
echo var_export($ao->getIteratorClass(), true), "\n";
if ('ArrayIterator' !== $ao->getIteratorClass()) {
exit(1);
}