array_filter_object.phpt [plain text]
--TEST--
Test array_filter() function : object functionality
--FILE--
<?php
echo "*** Testing array_filter() : object functionality ***\n";
class SimpleClass
{
public $var1 = 10;
public function check() {
return $var1;
}
}
class EmptyClass
{
}
abstract class AbstractClass
{
protected $var2 = 5;
abstract function emptyMethod();
}
class ChildClass extends AbstractClass
{
private $var3;
public function emptyMethod() {
echo "defined in child";
}
}
class FinalClass
{
private $var4;
final function finalMethod() {
echo 'This can not be overloaded';
}
}
class StaticClass
{
static $var5 = 5;
public static function staticMethod() {
echo 'this is static method';
}
}
function always_true($input)
{
return true;
}
function always_false($input)
{
return false;
}
$input = array(
new SimpleClass(),
new EmptyClass(),
new ChildClass(),
new FinalClass(),
new StaticClass()
);
var_dump( array_filter($input) );
var_dump( array_filter($input, "always_true") );
var_dump( array_filter($input, "always_false") );
echo "Done"
?>
--EXPECTF--
*** Testing array_filter() : object functionality ***
array(5) {
[0]=>
object(SimpleClass)#%d (1) {
["var1"]=>
int(10)
}
[1]=>
object(EmptyClass)#%d (0) {
}
[2]=>
object(ChildClass)#%d (2) {
["var3":"ChildClass":private]=>
NULL
["var2":protected]=>
int(5)
}
[3]=>
object(FinalClass)#%d (1) {
["var4":"FinalClass":private]=>
NULL
}
[4]=>
object(StaticClass)#%d (0) {
}
}
array(5) {
[0]=>
object(SimpleClass)#%d (1) {
["var1"]=>
int(10)
}
[1]=>
object(EmptyClass)#%d (0) {
}
[2]=>
object(ChildClass)#%d (2) {
["var3":"ChildClass":private]=>
NULL
["var2":protected]=>
int(5)
}
[3]=>
object(FinalClass)#%d (1) {
["var4":"FinalClass":private]=>
NULL
}
[4]=>
object(StaticClass)#%d (0) {
}
}
array(0) {
}
Done