3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SillyTestClass extends DOMElement{ public $foo=null; public function __construct($name,$value=null,$namespace=null){ echo "calling child construct...."; $this->foo="bar"; parent::__construct($name,$value,$namespace); } public function sayHello(){ echo "Why, hello there!"; } } $doc=new DOMDocument(); $doc->registerNodeClass('DOMElement','SillyTestClass'); $doc->loadHTML("<div><h1>Sample</h1></div>"); //THIS WORKS! CUSTOM CLASS BEING USED $doc->documentElement->firstChild->sayHello(); //THIS IS STILL NULL:( Never set by construct, no message saying construct was called either echo $doc->documentElement->firstChild->foo;
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.24, 7.4.0 - 7.4.13, 8.0.0
Why, hello there!