mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

Engine pitfall: the iter index is only updated by foreach opcodes, so the existing code that used it as an index for the nodes w.r.t. the start did not work properly. Fix it by using our own counter. Closes GH-18004.
31 lines
546 B
PHP
31 lines
546 B
PHP
--TEST--
|
|
Unpacking vs foreach behaviour
|
|
--EXTENSIONS--
|
|
dom
|
|
--FILE--
|
|
<?php
|
|
|
|
$dom = new DOMDocument;
|
|
$dom->loadXML('<root><a/><b/></root>');
|
|
|
|
echo "--- By foreach: ---\n";
|
|
|
|
foreach ($dom->documentElement->getElementsByTagName('*') as $node) {
|
|
var_dump($node->localName);
|
|
}
|
|
|
|
echo "--- By unpacking: ---\n";
|
|
|
|
$iter = $dom->documentElement->getElementsByTagName('*');
|
|
foreach ([...$iter] as $node) {
|
|
var_dump($node->localName);
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
--- By foreach: ---
|
|
string(1) "a"
|
|
string(1) "b"
|
|
--- By unpacking: ---
|
|
string(1) "a"
|
|
string(1) "b"
|