Bug #73981 [Opn->Ver]: __construct not being called on extensions of DOM base classes
| From: | cmb@php.net | Date: | Fri, 27 Jul 2018 12:24:00 +0000 |
| Subject: | Bug #73981 [Opn->Ver]: __construct not being called on extensions of DOM base classes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216499@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73981&edit=1
ID: 73981
Updated by: cmb@php.net
Reported by: work at timothytown dot com
Summary: __construct not being called on extensions of DOM
base classes
-Status: Open
+Status: Verified
Type: Bug
Package: DOM XML related
Operating System: windows
PHP Version: 7.1.1
Block user comment: N
Private report: N
New Comment:
Confirmed: <https://3v4l.org/sN59G>.
Previous Comments:
------------------------------------------------------------------------
[2017-01-23 18:13:03] work at timothytown dot com
Description:
------------
When a class is registered to a DOMDocument via the registerNodeClass method, the assigned class is
used to instance the return object from the DOMDOcument. However, the construct method of that class
is not called.
Test script:
---------------
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;
Expected result:
----------------
output "calling child construct..." //printed from child _construct
output "Why, hello there!" //printed from child method sayHello()
output "bar" //the value of child property after being assigned in constructor
Actual result:
--------------
//only the sayHello() method fires; construct doesn't happen
Why, hello there;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73981&edit=1