[PHP] SPL Countable count() not being called

2005-08-30 Thread Justin Francis
I 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.

Any ideas?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] SPL Countable count() not being called

2005-08-30 Thread Jay Blanchard
[snip]
class Collection implements Countable
{
  public function count()
  {
return 200;
  }   
}

$c = new Collection();
echo(count($c));
[/snip]

Shouldn't this be 

echo Collection-count($c);

or something like that?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SPL Countable count() not being called

2005-08-30 Thread Stut

Justin Francis wrote:

I 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SPL Countable count() not being called

2005-08-30 Thread Justin Francis

Stut wrote:


Justin Francis wrote:

I 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


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.


- Justin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SPL Countable count() not being called

2005-08-30 Thread Stut

Justin Francis wrote:


Stut wrote:


Should it not be $c-count() ?

-Stut


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.


Aha, gotcha. Thanks.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] SPL Countable count() not being called

2005-08-30 Thread Jay Blanchard
[snip]
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.
[/snip]

I was asleep earlierif $c is not an array 1 will be returned. $c is
one number (200), not an array.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [SPAM] - RE: [PHP] SPL Countable count() not being called - Bayesian Filter detected spam

2005-08-30 Thread Justin Francis

Jay Blanchard wrote:


[snip]
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.
[/snip]

I was asleep earlierif $c is not an array 1 will be returned. $c is
one number (200), not an array.
 

This would be true if the class does not implement the Countable 
interface. It does, however, and so 1 should not be returned, but 
instead, whatever number is returned from the count() method of the 
Collection class. See the SPL documentation at www.php.net/spl for more 
on how this is supposed to work.


- Justin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [SPAM] - RE: [PHP] SPL Countable count() not being called - Bayesian Filter detected spam

2005-08-30 Thread Chris

Justin Francis wrote:


Jay Blanchard wrote:


[snip]
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.
[/snip]

I was asleep earlierif $c is not an array 1 will be returned. $c is
one number (200), not an array.
 

This would be true if the class does not implement the Countable 
interface. It does, however, and so 1 should not be returned, but 
instead, whatever number is returned from the count() method of the 
Collection class. See the SPL documentation at www.php.net/spl for 
more on how this is supposed to work.


- Justin

SPL is still teething apparently. The docs don't always match the 
current functionality, and, I imagine, it can change from build to 
build. I've recently had some bumpy rides trying to get Recursive 
Iterators working the way I want.


I agree that it should work as you expect it to, and, in my opinion, 
it's a bug. My opinion doesn't count for too much, but there it is.


Chris
--Thinking about implementing the Countable interface now

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php