Re: When is an array not an array?



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 ;-)

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 to convert
itself into an actual array, but it doesn't seem to have that either.If, as whiskey says, the nodes are properties of the object, you can do
an explicit cast of the object to an array:

$arrayofnodes = (array)$nodelist;
--
PleegWat
Remove caps to reply

.



Relevant Pages

  • Re: [ANN] Rio 0.3.4
    ... > Will a modification of IRB with RIO, and a few other things, possibly result ... >> Ways to get the chomped lines of a file into an array ... >> Iterate over only the files in a directory ... >> * New Grande Selection parameter. ...
    (comp.lang.ruby)
  • [ANN] Rio 0.3.4
    ... Rio is a Ruby I/O convenience class wrapping much of the functionality ... Copy or append a file to a string ... Ways to get the chomped lines of a file into an array ... Iterate over only the files in a directory ...
    (comp.lang.ruby)
  • [ANN] Rio 0.3.7
    ... Rio is a Ruby I/O convenience class wrapping much of the functionality ... Copy or append a file to a string ... Ways to get the chomped lines of a file into an array ... Iterate over only the files in a directory ...
    (comp.lang.ruby)
  • [ANN] Rio 0.4.1
    ... = Rio - Ruby I/O Facilitator ... Iterate over the .rb files in a directory and its subdirectories. ... Return an array of the .rb files in a directory and its ... Copy or append a file to a string ...
    (comp.lang.ruby)
  • {ANN] Rio 0.4.0
    ... = Rio - Ruby I/O Facilitator ... Iterate over the .rb files in a directory and its subdirectories. ... Return an array of the .rb files in a directory and its ... Copy or append a file to a string ...
    (comp.lang.ruby)