Skip to content

dom_import_simplexml stub is wrong #16473

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns" xmlns:special="special-ns">
 <child reserved:attribute="Sample" special:attribute="Test" />
</root>
');
$spattr = $root->child->attributes('special-ns');
var_dump(Dom\import_simplexml($spattr));
?>

Resulted in this output:

object(Dom\Attr)#2 (22) {
  ["namespaceURI"]=>
  string(10) "special-ns"
  ["prefix"]=>
  string(7) "special"
  ["localName"]=>
  string(9) "attribute"
  ["name"]=>
  string(17) "special:attribute"
  ["value"]=>
  string(4) "Test"
  ["ownerElement"]=>
  string(22) "(object value omitted)"
  ["specified"]=>
  bool(true)
  ["nodeName"]=>
  string(17) "special:attribute"
  ["nodeValue"]=>
  string(4) "Test"
  ["nodeType"]=>
  int(2)
  ["parentNode"]=>
  string(22) "(object value omitted)"
  ["parentElement"]=>
  string(22) "(object value omitted)"
  ["childNodes"]=>
  string(22) "(object value omitted)"
  ["firstChild"]=>
  string(22) "(object value omitted)"
  ["lastChild"]=>
  string(22) "(object value omitted)"
  ["previousSibling"]=>
  string(22) "(object value omitted)"
  ["nextSibling"]=>
  NULL
  ["attributes"]=>
  NULL
  ["isConnected"]=>
  bool(true)
  ["ownerDocument"]=>
  string(22) "(object value omitted)"
  ["baseURI"]=>
  string(11) "about:blank"
  ["textContent"]=>
  string(4) "Test"
}

But I expected this output instead:

Fatal error: Dom\import_simplexml(): Return value must be of type Dom\Element, Dom\Attr returned in Unknown on line 0

To reproduce:

-d "zend_extension=/php-src/modules/opcache.so" -d "opcache.enable=1" -d "opcache.enable_cli=1" -d "opcache.jit=1215"

PHP Version

nightly

Operating System

ubuntu 22.04

Activity

  1. ndossche commented on Oct 17, 2024

    @ndossche
    Member

    dom_import_simplexml has this issue too. It's been wrong since PHP 8.0 at least, and the signature was inherited in 8.4-dev.

  2. changed the title [-]Unexpected result from Dom\import_simplexml in JIT[/-] [+]dom_import_simplexml stub is wrong[/+] on Oct 17, 2024
  3. added 3 commits that reference this issue on Oct 17, 2024
    632ebcc
    41af933
    c26d5f2
  4. added 2 commits that reference this issue on Oct 17, 2024
    55266d4
    b6f59d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions