Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM nodes changes identity #2962

Closed
goetas opened this issue Jun 17, 2014 · 6 comments
Closed

DOM nodes changes identity #2962

goetas opened this issue Jun 17, 2014 · 6 comments

Comments

@goetas
Copy link
Contributor

goetas commented Jun 17, 2014

Nodes created by PHP, when added to DOM, changes their identity.

$dom = new \DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement('root');
$dom->appendChild($root);

// expected to be TRUE, actually FALSE
var_dump($root === $dom->documentElement);
@goetas goetas changed the title Object inside DOMDocument is different from DOM nodes changes identity Jun 17, 2014
@sgolemon
Copy link
Contributor

Hrmmm. That's definitely an incompatibility with PHP5, but "fixing" it will take a fair amount of refactoring and probably just hurt perf in the end. Putting this on wishlist as we should probably find a way to make it work, but there's higher priority stuff to tackle.

@goetas
Copy link
Contributor Author

goetas commented Jun 18, 2014

There is also a PHP bug that is related to this.

It has a smaller side effect, but remains a unexpected behavior.

@ThomasWeinert
Copy link

Here is another effect that should be related to this issue. If you register an own class for a DOMNode descendant, the objected created by HHVM is still the superclass until the node is appended and changes its identity.

Example:

<?php
class MyElement extends \DOMElement {
 public function __get($name) { return $this->$name; } 
} 
$dom = new DOMDocument(); 
$dom->registerNodeClass('DOMElement', 'MyElement'); 
$createdNode = $dom->createElement('foo'); 
$appendedNode = $dom->appendChild($createdNode); 
var_dump(get_class($createdNode), get_class($appendedNode));

Expected:

string(9) "MyElement" 
string(9) "MyElement"

Actual:

string(10) "DOMElement" 
string(9) "MyElement"

@goetas
Copy link
Contributor Author

goetas commented Nov 5, 2014

@paulbiss Does it cover this?

$dom = new \DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement('root');
$dom->appendChild($root);

// expected to be TRUE, actually FALSE
var_dump($root === $dom->documentElement);

I can't see anything about it in 236c308.

Nodes identity was the original scope of this issue.

@paulbiss
Copy link
Contributor

paulbiss commented Nov 5, 2014

@goetas put the wrong issue number in the commit message

@paulbiss paulbiss reopened this Nov 5, 2014
@paulbiss
Copy link
Contributor

paulbiss commented Nov 5, 2014

My fix for #4126 should cover this (D1660716). It's up for internal review, I'll add this as a test.

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

No branches or pull requests

4 participants