[php-src] PR #24791: Fix GH-12168: Include leading non-element nodes in SimpleXML children() properties

From: Date: Tue, 27 Oct 2026 15:01:07 +0000
Subject: [php-src] PR #24791: Fix GH-12168: Include leading non-element nodes in SimpleXML children() properties
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-39977@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/24791 Author: Truta446 > Fixes GH-12168. > > For an element returned by children() > (SXE_ITER_CHILD), > sxe_get_prop_hash() started at the first *element* child (via > php_sxe_iterator_fetch()), but then walked the following siblings > with plain node->next. So processing instructions and comments > were included in var_dump() / ÊÐeÕ° > žƒ�G;®(array) / json_encode() only when they came > after the first element: > > | XML | (array) $root | (array) > $root->children() before | after | > |---|---|---|---| > | <c><x/><?hello world?></c> | x, hello > | x, hello | x, hello | > | <c><?hello world?><x/></c> | hello, x > | **x** | hello, x | > | <c><!-- c --><x/></c> | comment, x | > **x** | comment, x | > | <c>text</c> | 0 | (empty) | (empty) | > > The fix starts at the first child, like the SXE_ITER_NONE case > does, so children() now matches the element itself. Text nodes are > skipped for SXE_ITER_CHILD; otherwise an element containing only > text would start exposing that text through children(). Iteration > (foreach, count()) is unchanged, > since it goes through the iterator, not the property table. > > Targeting master because this changes > var_dump()/json_encode() output for > documents with a PI or comment before the first child element; I can retarget to PHP-8.4 if you > consider it a plain bug fix. > > Tests: new ext/simplexml/tests/gh12168.phpt (fails before, > passes after). ext/simplexml, > ext/dom and ext/libxml tests pass on > master (debug NTS, and debug + ASan) and on PHP-8.4 (debug + ASan, and debug ZTS).

« previous php.git-pulls (#39977) next »