3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dom = new DOMDocument(); $dom->loadXML( '<foobar><a:foo xmlns:a="urn:a">'. '<b:bar xmlns:b="urn:b"/></a:foo>'. '</foobar>' ); $xpath = new DOMXPath($dom); //get context node and check "a:foo" $context = $dom->documentElement->firstChild; var_dump($context->tagName); // try to override the context node $xpath->registerNamespace('a', 'urn:b'); var_dump( $xpath->evaluate( 'descendant-or-self::a:*', $context )->item(0)->tagName ); // use a prefix not used in context $xpath->registerNamespace('prefix', 'urn:b'); var_dump( $xpath->evaluate( 'descendant-or-self::prefix:*', $context )->item(0)->tagName );
Output for 5.1.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
string(5) "a:foo" string(5) "a:foo" string(5) "b:bar"
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.0 - 5.0.5
string(5) "a:foo" Fatal error: Call to undefined method DOMXPath::evaluate() in /in/QvGst on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/QvGst on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/QvGst on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/QvGst on line 20
Process exited with code 255.