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

Items in DOMNodelist not of registerNodeClass'd type #5412

Closed
theseer opened this issue May 27, 2015 · 4 comments
Closed

Items in DOMNodelist not of registerNodeClass'd type #5412

theseer opened this issue May 27, 2015 · 4 comments

Comments

@theseer
Copy link

theseer commented May 27, 2015

Using HHVM 3.7.0 the DOMNodelist returned by an XPath query does not honor the replacement of DOMElements via registerNodeClass.

class SampleElement extends \DOMElement {}

$dom = new DOMDocument();
$dom->registerNodeClass('DOMElement', 'SampleElement');
$dom->loadXML('<?xml version="1.0" ?><root />');

$xp = new DOMXPath($dom);
$list = $xp->query('/root');

var_dump(get_class($list->item(0)));

_Running it against php_
PHP 5.6.9 (cli) (built: May 15 2015 10:04:17)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

string(13) "SampleElement"

_Running it against hhvm_
HipHop VM 3.7.0 (rel)
Compiler: 1432365749_210873458
Repo schema: de2ad6572c3e61a7c559656fe50ddb42d096626d

string(10) "DOMElement"

@theseer
Copy link
Author

theseer commented May 27, 2015

Quick update to the sample code, now without XPath:

class SampleElement extends \DOMElement {}

$dom = new DOMDocument();
$dom->registerNodeClass('DOMElement', 'SampleElement');
$dom->loadXML('<?xml version="1.0" ?><root />');

$list = $dom->childNodes;

var_dump(get_class($list->item(0)));

@paulbiss
Copy link
Contributor

Okay, looks like I broke this when I changed the libxml memory model. I think we're failing to copy over the classmap (and other associated data) to the new domdoc when we loadXML() (and loadHTML()). Should be a pretty easy fix if someone wants to send a PR (otherwise I'll try to get to it soon).

dom_parse_document
dom_load_html

@theseer
Copy link
Author

theseer commented May 27, 2015

That means a potential workaround would be to simply re-register the nodeclass replacements after loading. At least until this is fixed.

theseer added a commit to theseer/fDOMDocument that referenced this issue May 27, 2015
@paulbiss
Copy link
Contributor

Yeah, that still works. We should really fix this though. http://3v4l.org/ITRfI

paulbiss added a commit that referenced this issue Aug 28, 2015
Summary: When loadXML or loadHTML is called, the DOMDocument should preserve any existing
settings.

Fixes #6034
Fixes #5412

Reviewed By: @jwatzman

Differential Revision: D2357973
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

2 participants