3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; $doc = 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";
Output for git.master, git.master_jit, rfc.property-hooks
Enter main() Enter bar() Enter foo() Warning: Undefined variable $dom in /in/qmr52 on line 38 Fatal error: Uncaught Error: Call to a member function registerNodeClass() on null in /in/qmr52:38 Stack trace: #0 /in/qmr52(50): foo() #1 /in/qmr52(60): bar() #2 {main} thrown in /in/qmr52 on line 38
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
49.7 ms | 401 KiB | 8 Q