3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class MyText extends DOMText { public $id; public static $next = 0; function __construct($text) { parent::__construct($text); $this->id = MyText::$next++; echo "Constructing DOMText #" . $this->id . ": " . $this->wholeText . "\n"; } function __destruct() { echo "Destructing DOMText #" . $this->id . ": " . $this->wholeText . "\n"; } } class MyElement extends DOMElement { public $id; public static $next = 0; function __construct($name) { parent::__construct($name); $this->id = MyText::$next++; echo "Constructing DOMElement #" . $this->id . ": " . $this->tagName . "\n"; } function __destruct() { echo "Destructing DOMElement #" . $this->id . ": " . $this->tagName . "\n"; } function info() { echo "Querying DOMElement #" . $this->id . ": " . $this->tagName . "\n"; } } function foo() { echo "Enter foo()\n"; $dom = new DOMDocument; $dom->registerNodeClass('DOMText', 'MyText'); $dom->registerNodeClass('DOMElement', 'MyElement'); $dom->appendChild($dom->createElement('foo')); $dom->appendChild($dom->createElement('bar')); echo "Leave foo()\n"; return $dom; } function bar() { echo "Enter bar()\n"; $d = foo(); $fooList = $d->getElementsByTagName('foo'); foreach ($fooList as $foo) { $foo->info(); } echo "Leave bar()\n"; } echo "Enter main()\n"; bar(); echo "Leave main()\n";
based on qmr52
Output for 5.3.0 - 7.2.0
Enter main() Enter bar() Enter foo() Destructing DOMElement #: foo Destructing DOMElement #: bar Leave foo() Querying DOMElement #: foo Leave bar() Destructing DOMElement #: foo Leave main()
Output for 5.2.6 - 5.2.17
Enter main() Enter bar() Enter foo() Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Leave foo() Querying DOMElement #: foo Leave bar() Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Leave main()
Output for 5.2.0 - 5.2.5
Enter main() Enter bar() Enter foo() Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Leave foo() Querying DOMElement #: foo Leave bar() Notice: Undefined property: MyElement::$tagName in /in/lFkYv on line 27 Destructing DOMElement #: Leave main()
Output for 5.0.0 - 5.1.6
Enter main() Enter bar() Enter foo() Fatal error: Call to undefined method DOMDocument::registerNodeClass() in /in/lFkYv on line 38
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/lFkYv on line 4
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_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/lFkYv on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/lFkYv on line 4
Process exited with code 255.