Skip to content

Regression: AOT DOMElement::setIdAttribute() — object::setidattribute / ExternalMethod segfault (ext/dom/element.c) #29257

Description

@PurHur

Category

stdlib · php-src-strict · ext/dom AOT bridge · pillar 4

Problem

VM and JIT match Zend for DOMElement::setIdAttribute() + getElementById(). Thin user-script AOT does not:

Repro Zend 8.2+ / VM / JIT AOT (phpc build, 2026-08-09 @7bd8ddf2e2)
$el = $doc->documentElement->firstChild; $el->setIdAttribute('id', true) works compile: Call to undefined method object::setidattribute()
$el = $doc->createElement('a'); … $el->setIdAttribute('id', true) works compiles via ExternalMethod fallthrough → segfault (internal_N)

Root cause: setIdAttribute* is implemented in VmDomInstanceInvoke / VmDomJitDispatch but is not in DomInstanceMethodJit::USER_SCRIPT_DIRECT_METHODS, so :object receivers (child props) fail at compile and typed DOMElement receivers bind the null ExternalMethod stub.

php-src reference

PHP implementation target

  • lib/JIT/DomInstanceMethodJit.php — add domelement::setidattribute{,ns,node} to user-script direct methods + registerKnownProxies
  • lib/JIT.php:object receiver ensureProxy/bind (peer #27108 attribute path)
  • Reuse Call\DomInstanceMethodVmDomInstanceInvoke (already dispatches setidattribute*); no new C

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/setid_aot.php <<'"'"'PHP'"'"'
<?php
$d = new DOMDocument();
$d->loadXML("<r><a id=\"x\"/><b id=\"x\"/></r>");
$a = $d->documentElement->firstChild;
$b = $a->nextSibling;
$a->setIdAttribute("id", true);
$b->setIdAttribute("id", true);
echo $d->getElementById("x")->nodeName, "\n";
PHP
php bin/vm.php /tmp/setid_aot.php
php bin/compile.php -o /tmp/setid_aot /tmp/setid_aot.php && /tmp/setid_aot'

Expect: a on VM and AOT (first-wins, #25275).

Done when

  • AOT compiles + runs the firstChild repro (output a)
  • AOT createElement typed path no longer segfaults
  • Smallest compliance/repro guard; php-src-strict
  • No new runtime/ C

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions