PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old July 15th, 2002, 09:28 AM
Fredrik Fredrik is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 Fredrik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 15th, 2002, 12:18 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: DOM - childNodes

I don't think it's possible until you can override the [] operators in php.. I might be wrong though.

Reply With Quote
  #3  
Old July 15th, 2002, 12:54 PM
Fredrik Fredrik is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 Fredrik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #4  
Old July 15th, 2002, 01:17 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
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.

Reply With Quote
  #5  
Old July 15th, 2002, 04:42 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > DOM - childNodes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway