Skip to content

Stdlib: xml_parse_into_struct() SAX struct builder (#3494) - #17844

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3494-xml-parse-into-struct
Jul 11, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-3494-xml-parse-into-struct

Conversation

@PurHur

@PurHur PurHur commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement xml_parse_into_struct() in ext/xml/ with PHP-in-PHP SAX-shaped struct walking (VmXmlStructBuilder).
  • Register by-ref parameter indices [2, 3] in BuiltinByRefParams so &$values / &$index writeback matches Zend.
  • Add repro, compliance .phpt, and unit tests.

php-src reference

  • ext/xml/xml.c — xml_parse_into_struct, xml_startElementHandler, xml_endElementHandler, xml_characterDataHandler

PHP implementation

  • ext/xml/xml_parse_into_struct.php, ext/xml/VmXmlStructBuilder.php, ext/xml/VmXml.php::parseIntoStruct()
  • lib/BuiltinByRefParams.php — xml_parse_into_struct → [2, 3]

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit test/unit/XmlParseIntoStructTest.php --no-configuration
php bin/vm.php test/repro/maintainer_gap_xml_parse_into_struct.php
php bin/vm.php -r "
\$vals = []; \$idx = [];
xml_parse_into_struct(xml_parser_create(), \"<root attr=\\\"v\\\">text<child/></root>\", \$vals, \$idx);
var_export(\$vals);
"'

Output (matches Zend case-folded tags/attributes):

PHPUnit ... OK (4 tests, 11 assertions)
ok
array (
  0 => array ('tag' => 'ROOT', 'type' => 'open', 'level' => 1, 'attributes' => array ('ATTR' => 'v'), 'value' => 'text'),
  1 => array ('tag' => 'CHILD', 'type' => 'complete', 'level' => 2),
  2 => array ('tag' => 'ROOT', 'type' => 'close', 'level' => 1),
)

Closes #3494

Made with Cursor

Implement xml_parse_into_struct() in ext/xml with PHP-in-PHP struct
walking (VmXmlStructBuilder), register by-ref params for values/index,
and add compliance + unit guards matching Zend case-folded index keys.

php-src: ext/xml/xml.c — xml_parse_into_struct
Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 75e6fd9 into master Jul 11, 2026
@PurHur
PurHur deleted the agent/issue-3494-xml-parse-into-struct branch July 11, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: ext/xml — xml_parser_create / xml_parse_into_struct SAX API (ext/xml/xml.c parity)

1 participant