#27929 [Asn->Csd]: SPL: change visibility of ArrayIterator::__construct

From: Date: Mon, 30 Aug 2004 18:32:27 +0000
Subject: #27929 [Asn->Csd]: SPL: change visibility of ArrayIterator::__construct
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65470@lists.php.net to get a copy of this message
ID: 27929 Updated by: helly@php.net Reported By: juwe at clasennet dot de -Status: Assigned +Status: Closed Bug Type: Feature/Change Request Operating System: * PHP Version: 5.0.0RC2 Assigned To: helly New Comment: Thank you for your bug report. This issue has already been fixed in the latest released version of PHP, which you can download at http://www.php.net/downloads.php Previous Comments: ------------------------------------------------------------------------ [2004-04-23 20:21:56] helly@php.net Here's a patch to fix the open SPL issues: http://marcus-boerger.de/php/ext/spl/spl-20040422.diff.txt It would be nice to have it tested prior to comitting it after RC2. ------------------------------------------------------------------------ [2004-04-09 09:05:18] juwe at clasennet dot de 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 ------------------------------------------------------------------------ [2004-04-09 08:18:13] helly@php.net 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

« previous php.bugs (#65470) next »