Re: SPL Countable count() not being called
| From: | Justin Francis | Date: | Tue, 30 Aug 2005 15:57:44 +0000 |
| Subject: | Re: SPL Countable count() not being called | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221599@lists.php.net to get a copy of this message | ||
Stut wrote:
Justin Francis wrote:No. By implementing the Countable interface, and implementing the count() method, the global count($c) function is supposed to call $c->count(). This is so the object can be treated like a countable array in the same manner. - JustinI have not been able to get count() to be called when I pass my Countable class to the count function. I am using PHP 5.1 Release Candidate 1. I am not sure if it is a bug, so I am posting here to see if anyone can help. -------------------------- class Collection implements Countable { public function count() { return 200; } } $c = new Collection(); echo(count($c)); ---------------------------- This code prints 1 out with no errors, when it should print out 200.Should it not be $c->count() ? -Stut