-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more testcase for array_filter() function
- Loading branch information
Raghubansh Kumar
committed
Oct 22, 2007
1 parent
7c21b37
commit 4846f7e
Showing
1 changed file
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--TEST-- | ||
Test array_filter() function : object functionality | ||
--FILE-- | ||
<?php | ||
/* Prototype : array array_filter(array $input [, callback $callback]) | ||
* Description: Filters elements from the array via the callback. | ||
* Source code: ext/standard/array.c | ||
*/ | ||
|
||
/* This file uses 'input' array with different types of objects and passes | ||
* it to array_filter() to test object functionality | ||
* i.e. object of simple class with members and functions | ||
* object of empty class | ||
* object of child class extending abstract class | ||
* object of class containing static member | ||
*/ | ||
|
||
echo "*** Testing array_filter() : object functionality ***\n"; | ||
|
||
// simple class with members - variable and method | ||
class SimpleClass | ||
{ | ||
public $var1 = 10; | ||
public function check() { | ||
return $var1; | ||
} | ||
} | ||
|
||
// class without members | ||
class EmptyClass | ||
{ | ||
} | ||
|
||
// abstract class | ||
abstract class AbstractClass | ||
{ | ||
protected $var2 = 5; | ||
abstract function emptyMethod(); | ||
} | ||
|
||
// class deriving above abstract class | ||
class ChildClass extends AbstractClass | ||
{ | ||
private $var3; | ||
public function emptyMethod() { | ||
echo "defined in child"; | ||
} | ||
} | ||
|
||
// class with final method | ||
class FinalClass | ||
{ | ||
private $var4; | ||
final function finalMethod() { | ||
echo 'This can not be overloaded'; | ||
} | ||
} | ||
|
||
// class with static members | ||
class StaticClass | ||
{ | ||
static $var5 = 5; | ||
public static function staticMethod() { | ||
echo 'this is static method'; | ||
} | ||
} | ||
|
||
// Callback function which returns always true | ||
function always_true($input) | ||
{ | ||
return true; | ||
} | ||
|
||
// Callback function which returns always false | ||
function always_false($input) | ||
{ | ||
return false; | ||
} | ||
|
||
// 'input' array containing objects as elements | ||
$input = array( | ||
new SimpleClass(), | ||
new EmptyClass(), | ||
new ChildClass(), | ||
new FinalClass(), | ||
new StaticClass() | ||
); | ||
|
||
|
||
// with default callback | ||
var_dump( array_filter($input) ); | ||
|
||
// with always_true callback function | ||
var_dump( array_filter($input, "always_true") ); | ||
|
||
// with always_false callback function | ||
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:private"]=> | ||
NULL | ||
["var2:protected"]=> | ||
int(5) | ||
} | ||
[3]=> | ||
object(FinalClass)#%d (1) { | ||
["var4: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:private"]=> | ||
NULL | ||
["var2:protected"]=> | ||
int(5) | ||
} | ||
[3]=> | ||
object(FinalClass)#%d (1) { | ||
["var4:private"]=> | ||
NULL | ||
} | ||
[4]=> | ||
object(StaticClass)#%d (0) { | ||
} | ||
} | ||
array(0) { | ||
} | ||
Done |