Re: {Spam?} Re: [PHP] Anyone using SPL Iterators?

From: Date: Wed, 22 Sep 2004 16:20:02 +0000
Subject: Re: {Spam?} Re: [PHP] Anyone using SPL Iterators?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-197580@lists.php.net to get a copy of this message
Curt Zirzow wrote:
* Thus wrote John Holmes:
A later example implements ArrayAccess and IteratorAggregate and then says you can use count($A), but it doesn't work for my tests. It always returns 1.
That example i think is minor mistake. As noted in the example above you have to call pass ->getIterator() to count(). count() doesn't detect if the object if getIterator is present, its just returns 1 since $A isn't an array. BUT.. this works: echo count( (array)$A ); Yet, even if you use count($A->getIterator()) or cast the object, the indexes (0,1,2) arn't defined, unlesss you redifine the offsetGet() to get the proper one.
So is there an implementation so that you can use count() on the "object" and have it treated like an array? i.e. you define what the count should return? The ideal solution, as I understand all of this, would be to have $A = new ArrayReloaded(array('one','two','three')); and have count($A) return 3. Do you know how that'd be done? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#197580) next »