Note Submitter: nobody at dontlikespam dot com
----
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.
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|