ID:               27929
 User updated by:  juwe at clasennet dot de
 Reported By:      juwe at clasennet dot de
 Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Does not matter
 PHP Version:      5CVS-2004-04-09 (dev)
 New Comment:

First of all, thanks for Your kind reply.

If I could use ArrayObject for anything else than producing an
iterator, I'd agree, that there is indeed no necessity for any further
possibility to create an iterator for an array. In this case I'd simply
use ArrayObject instead of Arrays and I'd be done with that one. 



But as it is now, I do have to convert my array into an object just for
looping through it outside of my class.



Let me present an example for this:



<?php

  class MyClass implements IteratorAggregate

  {

    private $myData;

    function __construct()

    {

      $this->myData=array();

    }

    public function addValue($value)

    {

      /* do something with value */

      $this->myData[]=$value*2;

    }

    public function getIterator()

    {

      /* works:*/

      $tmpObject=new ArrayObject($this->myData);

      return $tmpObject->getIterator();

      /* fails:

       return (new ArrayObject($this->myData))->getIterator();

       return new ArrayIterator($this->myData);

       */

    }

  }



I mean, it is no problem to create one new temporary var vor the
ArrayObject, but in the end I have the feeling, that its not, well
maybe "perfect" is the right term, but a bloody workaround.



At the moment I do see four possible solutions:



1) Allow creating own instances from ArrayIterator



2) Add a static method to ArrayObject to create array-Iterators
directly for any array supplied.



3) Add much more functionality to ArrayObject. (At least adding,
accessing and removing elements would be fine.)



4) Make ArrayObject usable with all the existing array functions (e.g.
sort(), etc.).



Yours Jens


Previous Comments:
------------------------------------------------------------------------

[2004-04-09 08:18:13] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

ArrayObject encapsulates the array and ArrayIterator depends on that
encapsulation. For the moment i do not

see any reason to change that behavior.

------------------------------------------------------------------------

[2004-04-09 07:02:47] juwe at clasennet dot de

Description:
------------
Hello,



when I just tested the SPL I found a necessity to create an iterator
for an existing array. Since ArrayIterator::__construct() is currently
declared private, I've first had to create a completely unnecessary
(well, at least from my point of view) instance of ArrayObject, just to
produce an Iterator with ArrayObject::getInstance().



Could someone please have a look at that one and decide if it is
possible to allow public access on ArrayIterators without the necessety
to create foreign objects in before?



I know this is just a minor issue at the moment, but I'd prefer such
things beeing changed, before they are used in a productive
environment.



Thanks 

Jens Clasen



P.S.: Please excuse my bad english - I am no native speaker.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27929&edit=1

Reply via email to