So that count($object)
will return the number of records in it
views:
144answers:
2
+7
A:
If you have Standard PHP Library installed you should be able to simply implement Countable in your class and then define the count() function:
class foo implements Countable {
...
public function count() {
# do stuff here
return $count;
}
}
Read more about the SPL here: http://www.php.net/manual/en/book.spl.php
More about the Countable interface here: http://php.net/manual/en/countable.count.php
thetaiko
2010-02-19 16:13:02
+3
A:
Take a look at Countable::count
class MyClass implements Countable {
public function count() {
//return count
}
}
$c = new MyClass();
count($c); //calls $c->count();
Yacoby
2010-02-19 16:13:25