|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
DOM - childNodes
Anyone who knows alot about W3's Document Object Model - look at this thread:
I'm working on an own DOM extension to PHP. Using PHP classes. Now I have encounterd a problem with the "NodeList" interface (read class). Every DOM - Object that inherit from the "Node" && can contain children has a property called "childNodes". This property is a member of the "NodeList" interface. (read an member of the class NodeList, therefor an object) So for ex. if I want to reach the second child of the current object I use the following syntax: $currentobj->childNodes->item(2) Now to my problem: The W3 specification aslo say thet you can reach a child with brackets like an array: $currentobject->childNodes[2] My question is how to do that in PHP? In Ecmascript (javascript) this is very easy because array's ARE objects. (in PHP that would mean the the arrays would be a class) How do you make an object work like an array an the other way around? Is there a way to do this? So that you can create an object like this: $myobj = new someclass(); and then give it array info like this: $myobj[0] = "somestring"; echo $myobj still says "object". Is this possible? Thans for any replys. |
|
#2
|
|||
|
|||
|
RE: DOM - childNodes
I don't think it's possible until you can override the [] operators in php.. I might be wrong though.
|
|
#3
|
|||
|
|||
|
RE: DOM - childNodes
Then how are the PHP developers gonna do with their DOMXML extension?
Are they gonna "hardcode" it through c++? (or perhaps the zend) Well thanks for the reply! |
|
#4
|
|||
|
|||
|
RE: DOM - childNodes
from the php manual :
----------- DomNode->child_nodes (unknown) DomNode->child_nodes -- Returns children of node Description array DomNode->child_nodes ( void) Returns all children of the node. --------- I'm assuming that they only use an array, and not and object - ie. you can't use $currentobj->child_nodes->item(2) unless they created a function in $currentobj called childNodes() that returns a childnodes object.. but it would have to be called differently to child_nodes().. Interesting stuff.. I never knew this even existed ;) so if i'm talking total trash, then you know why. |
|
#5
|
|||
|
|||
|
RE: DOM - childNodes
Yeah, as of the Zend Engine 2 (when PHP 4.3.0 is released) you can use factory methods. (methods that return objects.)
When you use factory methods with Zend Engine 1 you have to do it like this: $newobj = $obj->factory(); $newobj->method(); With Zend Engine 2 you can use real factory methods like this: $obj->factory()->method(); //when you try to do this with Zend engine 1 you'll get an error. But that is not the way the childNodes property works. It doesn't use any factory methods, it is a member of another class BUT can also be reached by brackets (as an array) There is the dilemma. I don't really have the right knowledge in the Zend to understand how arrays are build for PHP, and how you can (if you can) manipulate them. But anyway, thanks for the replys. /Fredrik |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > DOM - childNodes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|