note 78342 added to function.dom-domdocument-registernodeclass

From: Date: Sun, 07 Oct 2007 20:59:43 +0000
Subject: note 78342 added to function.dom-domdocument-registernodeclass
Groups: php.notes 
Request: Send a blank email to php-notes+get-131208@lists.php.net to get a copy of this message
Oh, and there's another issue. Most "objects" in PHP's 5 DOM extends DOMNode class. But, if you create your version of that class (eg. MyDOMNode extends DOMNode) and register it to DOMDocument with this function, your methods will be only available on DOMNode type objects and none of standard objects that extends that one. Eg.: you want that objects DOMElement, DOMAttr and DOMText have same method (let's call it "MyMethod"). So what you think you sould do? In normal OOP you implement "MyMethod" to the DOMNode class (which is extended by all others) and you should be able to call DOMElement->MyMethod(), DOMAttr->MyMethod() and so on. BUT in PHP DOM you can't do that: <?php class MyDOMNode extends DOMNode { public function MyMethod(){ echo "HELLO"; } } // Create DOMDocument, registerNodeClass MyDOMNode // Get some text node and some tag node $textNode->myMethod(); // DOMText object $tagNode->myMethod(); // DOMElement object ?> Result? Both fails with no such method error. Why if both classes (DOMText and DOMElement) extends DOMNode which I just have replaced with my own that contains this method? So what one should do if he want same own method on all DOM objects that extends DOMNode? First thing that come to mind is to create one class eg. "MyDOMClass" that contains that method and spread it in all needed native classes. But... in PHP class could be extended only by ONE other class, and you MUST extend your replacement with oryginal one - there is no room to extend it with your global MyDOMClass too. The only way I see is: <?php class myDOMElement extends DOMElement { public function MyMethod(){} } class myDOMAttr extends DOMAttr { public function MyMethod(){} } class myDOMText extends DOMText { public function MyMethod(){} } // AND SO ON FOR OTHER TYPES ?> Object-Oriented-Programming... yea sure. Dear developers of this extension, one question: have you ever seen OOP in action? I think not. ---- Server IP: 82.160.94.10 Probable Submitter: 81.210.72.12 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-registernodeclass.php Edit -- https://master.php.net/note/edit/78342 Del: integrated -- https://master.php.net/note/delete/78342/integrated Del: useless -- https://master.php.net/note/delete/78342/useless Del: bad code -- https://master.php.net/note/delete/78342/bad+code Del: spam -- https://master.php.net/note/delete/78342/spam Del: non-english -- https://master.php.net/note/delete/78342/non-english Del: in docs -- https://master.php.net/note/delete/78342/in+docs Del: other reasons-- https://master.php.net/note/delete/78342 Reject -- https://master.php.net/note/reject/78342 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131208) next »