Why can't people who implement the Countable interface use $obj->count() instead of count($obj)?
I just don't see any reason to overload count() in this scenario. It does set a precendent to overload all of array.c and as I mention, there is no reason why count() is better than $obj->count() as objects aren't completely interchangeable with arrays anyway and you'd be checking if that interface is implemented.
I really don't want to get carried away with all of this internal overloading. I thought we agreed a few months ago that we won't start adding more and more such stuff especially when there is (IMO) not very much value in it.
Andi
At 03:30 PM 11/20/2004 +0100, Marcus Boerger wrote:
Hello Christian,
Saturday, November 20, 2004, 2:59:07 PM, you wrote:
> Marcus Boerger wrote: >> We already decided not to allow ArrayAccess implementations to work
> Ok, excuse my ignorance, so what's the list of functions/constructs > affected by SPL?
> - foreach > - [] > - count()
> What else? Are there plan to extend that at a later stage? [ Simply > point me to an online document if it exists, I missed it so far. ]
There is non because noone so far wrote something about the negine magic. Mabe you should look here at the engine description in Zend directory of you PHP source.
In detail: - foreach is overloaded by the interfaces Traversable, Iterator, IteratorAggregate (all three engine level). - [] is overloaded by interface ArrayAccess (this is engine level only count() is missing here) - count() is overloaded by SPL interface Countable.
Othere real magic features are: - __ get(), __set(), __call() which a only controlled by a provided implementation and handled by the engine - __serialize(), __unserialize() controlled by a provided implementation and handled by ext/standard
So obviously there is a clear desticntion in the naming: - __*() function are only controlled by a given implementation through the engine - Other things (non __*() function) are controlled by an Interface
The reason for this might be BC and that we didn't had Interfaces when __get/__set/__call were implemented. To make it real we should chnage the interceptors to be controlled by interfaces too. But in the other hand thereis no real enforcement needed.
Coming back to SPL this means - as said already - that it only utilizes the engine features. But as always there is an exception and this exception is Countable / count().
>> ArrayAccess usable. However apart from coun()/Countable in general SPL >> only makes engine features usefull. Since count()/sizeof() is a lnagugae
> I'm not sure what you are trying to say here. I'm not against SPL.
>> or even compiler feature in ost other languages it should result in it >> being moved to the engine in PHP.
> No idea what you mean here. But that's probably not important as I'm > sure you and Andi are doing the Right Thing(tm).
In other words i meant that the Countable interface should be moved to the engine.
Best regards, Marcus mailto:[EMAIL PROTECTED]
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php