countable

PHP: how can I sort and filter an “array”, that is an Object, implementing ArrayAccess?

我的梦境 提交于 2019-12-23 13:11:31
问题 I have an object that is a collection of objects, behaving like an array. It's a database result object. Something like the following: $users = User::get(); foreach ($users as $user) echo $user->name . "\n"; The $users variable is an object that implements ArrayAccess and Countable interfaces. I'd like to sort and filter this "array", but I can't use array functions on it: $users = User::get(); $users = array_filter($users, function($user) {return $user->source == "Twitter";}); => Warning:

Overload the behavior of count() when called on certain objects [duplicate]

ぐ巨炮叔叔 提交于 2019-11-30 11:17:25
Possible Duplicate: Count elements for objects implementing ArrayAccess using count()? In PHP 5, you can use magic methods, overload some classes, etc. In C++, you can implement functions that exist as long as the argument types are different. Is there a way to do this in PHP? An example of what I'd like to do is this: class a { function a() { $this->list = array("1", "2"); } } $blah = new a(); count($blah); I would like blah to return 2. IE count the values of a specific array in the class. So in C++, the way I would do this might look like this: int count(a varName) { return count(varName-

Overload the behavior of count() when called on certain objects [duplicate]

帅比萌擦擦* 提交于 2019-11-29 16:56:33
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Count elements for objects implementing ArrayAccess using count()? In PHP 5, you can use magic methods, overload some classes, etc. In C++, you can implement functions that exist as long as the argument types are different. Is there a way to do this in PHP? An example of what I'd like to do is this: class a { function a() { $this->list = array("1", "2"); } } $blah = new a(); count($blah); I would like blah to

phpmyadmin - count(): Parameter must be an array or an object that implements Countable

早过忘川 提交于 2019-11-26 07:50:51
问题 I\'ve uploaded the backup to a table, opening the table I see this: Warning in ./libraries/sql.lib.php#601 count(): Parameter must be an array or an object that implements Countable Backtrace ./libraries/sql.lib.php#2038: PMA_isRememberSortingOrder(array) ./libraries/sql.lib.php#1984: PMA_executeQueryAndGetQueryResponse( array, boolean true, string \'alternativegirls\', string \'tgp_photo\', NULL, NULL, NULL, NULL, NULL, NULL, string \'\', string \'./themes/pmahomme/img/\', NULL, NULL, NULL,