Re: When is an array not an array?
- From: PleegWat <pleegwat@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 10:40:46 +0100
In article <1162285622.826148.302460@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
whiskey says...
On Oct 31, 12:27 am, PleegWat
<pleeg...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
In article <q13ck2d3tc2204gdsi3db9q0bds510p...@xxxxxxx>, Andy Hassall
says...
Failing that, it'd be somewhat useful if DOMNodeList had a method toIf, as whiskey says, the nodes are properties of the object, you can do
convert itself into an actual array, but it doesn't seem to have that
either.
an explicit cast of the object to an array:
$arrayofnodes = (array)$nodelist;
I dare say you can not cast a DOMNodeList to an array. Because, when
converting an object to an array, you get the properties of the object.
And DOMNodeList has only one porperty, which is "length" (and useless
in this context).
Anyway, I can't find any reason why one will ever need to convert a
DOMNodeList to an array since it provides a method to retrieve a node
specified by it's index ("item()"). Moreover, PHP5 offers the ability
to iterate through objects. So why this fuss ?
PleegWat, I never said nodes are properties. All I said was that PHP5
adds the ability to iterate the visible properties of an object. But
that's the default. You can customize the way PHP iterates through
objects by implementing the "Iterator" or "IteratorAggregate"
interfaces ;-)
(top-posting fixed)
Sorry, misunderstood you then. I did take a quick look at the manual but
I couldn't find anything about hte DOMNodeList class.
--
PleegWat
Remove caps to reply
.
- Follow-Ups:
- Re: When is an array not an array?
- From: whiskey
- Re: When is an array not an array?
- References:
- When is an array not an array?
- From: Andrew C
- Re: When is an array not an array?
- From: Andy Hassall
- Re: When is an array not an array?
- From: PleegWat
- Re: When is an array not an array?
- From: whiskey
- When is an array not an array?
- Prev by Date: Re: Get http response codes
- Next by Date: Re: When is an array not an array?
- Previous by thread: Re: When is an array not an array?
- Next by thread: Re: When is an array not an array?
- Index(es):
Relevant Pages
|