diff options
Diffstat (limited to 'ext/standard/tests/class_object')
71 files changed, 5988 insertions, 0 deletions
diff --git a/ext/standard/tests/class_object/AutoInterface.inc b/ext/standard/tests/class_object/AutoInterface.inc new file mode 100644 index 0000000..f1e5b1f --- /dev/null +++ b/ext/standard/tests/class_object/AutoInterface.inc @@ -0,0 +1,5 @@ +<?php + +Interface AutoInterface {} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/AutoLoaded.inc b/ext/standard/tests/class_object/AutoLoaded.inc new file mode 100644 index 0000000..52e6671 --- /dev/null +++ b/ext/standard/tests/class_object/AutoLoaded.inc @@ -0,0 +1,5 @@ +<?php + +class AutoLoaded {} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/AutoTest.inc b/ext/standard/tests/class_object/AutoTest.inc new file mode 100644 index 0000000..0627096 --- /dev/null +++ b/ext/standard/tests/class_object/AutoTest.inc @@ -0,0 +1,13 @@ +<?php + +class autoTest { + public static $bob = "bob"; + + public function __get($name) { + echo "attempt to access $name\n"; + return "foo"; + } + +} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/AutoTrait.inc b/ext/standard/tests/class_object/AutoTrait.inc new file mode 100644 index 0000000..698e975 --- /dev/null +++ b/ext/standard/tests/class_object/AutoTrait.inc @@ -0,0 +1,5 @@ +<?php + +trait AutoTrait {} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_basic_001.phpt b/ext/standard/tests/class_object/class_exists_basic_001.phpt new file mode 100644 index 0000000..4cb6cbd --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_basic_001.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test class_exists() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing class_exists() : basic functionality ***\n"; + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +echo "Calling class_exists() on non-existent class with autoload explicitly enabled:\n"; +var_dump( class_exists('C', true) ); +echo "\nCalling class_exists() on existing class with autoload explicitly enabled:\n"; +var_dump( class_exists('stdclass', true) ); + +echo "\nCalling class_exists() on non-existent class with autoload explicitly enabled:\n"; +var_dump( class_exists('D', false) ); +echo "\nCalling class_exists() on existing class with autoload explicitly disabled:\n"; +var_dump( class_exists('stdclass', false) ); + +echo "\nCalling class_exists() on non-existent class with autoload unspecified:\n"; +var_dump( class_exists('E') ); +echo "\nCalling class_exists() on existing class with autoload unspecified:\n"; +var_dump( class_exists('stdclass') ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : basic functionality *** +Calling class_exists() on non-existent class with autoload explicitly enabled: +In __autoload(C) +bool(false) + +Calling class_exists() on existing class with autoload explicitly enabled: +bool(true) + +Calling class_exists() on non-existent class with autoload explicitly enabled: +bool(false) + +Calling class_exists() on existing class with autoload explicitly disabled: +bool(true) + +Calling class_exists() on non-existent class with autoload unspecified: +In __autoload(E) +bool(false) + +Calling class_exists() on existing class with autoload unspecified: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_error_001.phpt b/ext/standard/tests/class_object/class_exists_error_001.phpt new file mode 100644 index 0000000..99c0b89 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test class_exists() function : error conditions (wrong number of arguments) +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/** + * Test wrong number of arguments + */ + +echo "*** Testing class_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing class_exists() function with Zero arguments --\n"; +var_dump( class_exists() ); + +//Test class_exists with one more than the expected number of arguments +echo "\n-- Testing class_exists() function with more than expected no. of arguments --\n"; +$classname = 'string_val'; +$autoload = true; +$extra_arg = 10; +var_dump( class_exists($classname, $autoload, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : error conditions *** + +-- Testing class_exists() function with Zero arguments -- + +Warning: class_exists() expects at least 1 parameter, 0 given in %s on line 16 +NULL + +-- Testing class_exists() function with more than expected no. of arguments -- + +Warning: class_exists() expects at most 2 parameters, 3 given in %s on line 23 +NULL +Done diff --git a/ext/standard/tests/class_object/class_exists_variation_001.phpt b/ext/standard/tests/class_object/class_exists_variation_001.phpt new file mode 100644 index 0000000..c9146ba --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_001.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test class_exists() function : usage variations - unexpected types for agument 1 +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing class_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$autoload = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for classname + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( class_exists($value, $autoload) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +In __autoload(0) +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value 12345 +In __autoload(12345) +bool(false) + +Arg value -2345 +In __autoload(-2345) +bool(false) + +Arg value 10.5 +In __autoload(10.5) +bool(false) + +Arg value -10.5 +In __autoload(-10.5) +bool(false) + +Arg value 101234567000 +In __autoload(101234567000) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(1.07654321E-9) +bool(false) + +Arg value 0.5 +In __autoload(0.5) +bool(false) +Error: 8 - Array to string conversion, %sclass_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 2 - class_exists() expects parameter 1 to be string, object given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_variation_002.phpt b/ext/standard/tests/class_object/class_exists_variation_002.phpt new file mode 100644 index 0000000..ae9de15 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_002.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test class_exists() function : usage variations - unexpected types for agument 2 +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing class_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$classname = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for autoload + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( class_exists($classname, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(71) +Error: 8 - Undefined variable: unset_var, %s(74) + +Arg value 0 +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value 12345 +In __autoload(string_val) +bool(false) + +Arg value -2345 +In __autoload(string_val) +bool(false) + +Arg value 10.5 +In __autoload(string_val) +bool(false) + +Arg value -10.5 +In __autoload(string_val) +bool(false) + +Arg value 101234567000 +In __autoload(string_val) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(string_val) +bool(false) + +Arg value 0.5 +In __autoload(string_val) +bool(false) +Error: 8 - Array to string conversion, %sclass_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %sclass_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(80) + +Arg value +Error: 2 - class_exists() expects parameter 2 to be boolean, object given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_variation_003.phpt b/ext/standard/tests/class_object/class_exists_variation_003.phpt new file mode 100644 index 0000000..0745601 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test class_exists() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class caseSensitivityTest {} +var_dump(class_exists('casesensitivitytest')); + +echo "Done" +?> +--EXPECTF-- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/forward_static_call_001.phpt b/ext/standard/tests/class_object/forward_static_call_001.phpt new file mode 100644 index 0000000..2b3a8dd --- /dev/null +++ b/ext/standard/tests/class_object/forward_static_call_001.phpt @@ -0,0 +1,83 @@ +--TEST-- +forward_static_call() called from outside of a method. +--FILE-- +<?php + +class A +{ + const NAME = 'A'; + public static function test() { + echo static::NAME, "\n"; + } +} + +class B extends A +{ + const NAME = 'B'; + + public static function test() { + echo self::NAME, "\n"; + forward_static_call(array('parent', 'test')); + } + + public static function test2() { + echo self::NAME, "\n"; + forward_static_call(array('self', 'test')); + } + + public static function test3() { + echo self::NAME, "\n"; + forward_static_call(array('A', 'test')); + } +} + +class C extends B +{ + const NAME = 'C'; + + public static function test() + { + echo self::NAME, "\n"; + forward_static_call(array('A', 'test')); + } +} + +A::test(); +echo "-\n"; +B::test(); +echo "-\n"; +B::test2(); +echo "-\n"; +B::test3(); +echo "-\n"; +C::test(); +echo "-\n"; +C::test2(); +echo "-\n"; +C::test3(); + +?> +===DONE=== +--EXPECTF-- +A +- +B +B +- +B +B +B +- +B +B +- +C +C +- +B +B +C +- +B +C +===DONE=== diff --git a/ext/standard/tests/class_object/forward_static_call_002.phpt b/ext/standard/tests/class_object/forward_static_call_002.phpt new file mode 100644 index 0000000..58c4efd --- /dev/null +++ b/ext/standard/tests/class_object/forward_static_call_002.phpt @@ -0,0 +1,21 @@ +--TEST-- +forward_static_call() from outside of a class method. +--FILE-- +<?php + +class A +{ + public static function test() { + echo "A\n"; + } +} + +function test() { + forward_static_call(array('A', 'test')); +} + +test(); + +?> +--EXPECTF-- +Fatal error: Cannot call forward_static_call() when no class scope is active in %s on line %d diff --git a/ext/standard/tests/class_object/forward_static_call_003.phpt b/ext/standard/tests/class_object/forward_static_call_003.phpt new file mode 100644 index 0000000..2ea102e --- /dev/null +++ b/ext/standard/tests/class_object/forward_static_call_003.phpt @@ -0,0 +1,51 @@ +--TEST-- +forward_static_call() calling outside of the inheritance chain. +--FILE-- +<?php + +class A +{ + const NAME = 'A'; + public static function test() { + echo static::NAME, "\n"; + } +} + +class B extends A +{ + const NAME = 'B'; + + public static function test() { + echo self::NAME, "\n"; + forward_static_call(array('parent', 'test')); + } +} + +class C +{ + const NAME = 'C'; + + public static function test() { + echo self::NAME, "\n"; + forward_static_call(array('B', 'test')); + } +} + +A::test(); +echo "-\n"; +B::test(); +echo "-\n"; +C::test(); + +?> +===DONE=== +--EXPECTF-- +A +- +B +B +- +C +B +B +===DONE=== diff --git a/ext/standard/tests/class_object/get_class_error_001.phpt b/ext/standard/tests/class_object/get_class_error_001.phpt new file mode 100644 index 0000000..5550995 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_error_001.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test get_class() function : error conditions - wrong number of arguments. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class() : error conditions ***\n"; + +//Test get_class with one more than the expected number of arguments +echo "\n-- Testing get_class() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$extra_arg = 10; +var_dump( get_class($object, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class() : error conditions *** + +-- Testing get_class() function with more than expected no. of arguments -- + +Warning: get_class() expects at most 1 parameter, 2 given in %s on line 14 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_001.phpt b/ext/standard/tests/class_object/get_class_methods_basic_001.phpt new file mode 100644 index 0000000..b2b87af --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_001.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test basic behaviour with existing class and non-existent class. + */ + +echo "*** Testing get_class_methods() : basic functionality ***\n"; + +class C { + function f() {} + function g() {} + function h() {} +} + +echo "Argument is class name:\n"; +var_dump( get_class_methods("C") ); +echo "Argument is class instance:\n"; +$c = new C; +var_dump( get_class_methods($c) ); + +class D {} +echo "Argument is name of class which has no methods:\n"; +var_dump( get_class_methods("D") ); + +echo "Argument is non existent class:\n"; +var_dump( get_class_methods("NonExistent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : basic functionality *** +Argument is class name: +array(3) { + [0]=> + string(1) "f" + [1]=> + string(1) "g" + [2]=> + string(1) "h" +} +Argument is class instance: +array(3) { + [0]=> + string(1) "f" + [1]=> + string(1) "g" + [2]=> + string(1) "h" +} +Argument is name of class which has no methods: +array(0) { +} +Argument is non existent class: +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_002.phpt b/ext/standard/tests/class_object/get_class_methods_basic_002.phpt new file mode 100644 index 0000000..441bb45 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_002.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test behaviour with various visibility levels. + */ + +class C { + private function privC() {} + protected function protC() {} + public function pubC() {} + + public static function testFromC() { + echo "Accessing C from C:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from C:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from C:\n"; + var_dump(get_class_methods("X")); + } +} + +class D extends C { + private function privD() {} + protected function protD() {} + public function pubD() {} + + public static function testFromD() { + echo "Accessing C from D:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from D:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from D:\n"; + var_dump(get_class_methods("X")); + } +} + +class X { + private function privX() {} + protected function protX() {} + public function pubX() {} + + public static function testFromX() { + echo "Accessing C from X:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from X:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from X:\n"; + var_dump(get_class_methods("X")); + } +} + +echo "Accessing D from global scope:\n"; +var_dump(get_class_methods("D")); + +C::testFromC(); +D::testFromD(); +X::testFromX(); + +echo "Done"; +?> +--EXPECTF-- +Accessing D from global scope: +array(4) { + [0]=> + string(4) "pubD" + [1]=> + string(9) "testFromD" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing C from C: +array(4) { + [0]=> + string(5) "privC" + [1]=> + string(5) "protC" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing D from C: +array(7) { + [0]=> + string(5) "protD" + [1]=> + string(4) "pubD" + [2]=> + string(9) "testFromD" + [3]=> + string(5) "privC" + [4]=> + string(5) "protC" + [5]=> + string(4) "pubC" + [6]=> + string(9) "testFromC" +} +Accessing X from C: +array(2) { + [0]=> + string(4) "pubX" + [1]=> + string(9) "testFromX" +} +Accessing C from D: +array(3) { + [0]=> + string(5) "protC" + [1]=> + string(4) "pubC" + [2]=> + string(9) "testFromC" +} +Accessing D from D: +array(7) { + [0]=> + string(5) "privD" + [1]=> + string(5) "protD" + [2]=> + string(4) "pubD" + [3]=> + string(9) "testFromD" + [4]=> + string(5) "protC" + [5]=> + string(4) "pubC" + [6]=> + string(9) "testFromC" +} +Accessing X from D: +array(2) { + [0]=> + string(4) "pubX" + [1]=> + string(9) "testFromX" +} +Accessing C from X: +array(2) { + [0]=> + string(4) "pubC" + [1]=> + string(9) "testFromC" +} +Accessing D from X: +array(4) { + [0]=> + string(4) "pubD" + [1]=> + string(9) "testFromD" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing X from X: +array(4) { + [0]=> + string(5) "privX" + [1]=> + string(5) "protX" + [2]=> + string(4) "pubX" + [3]=> + string(9) "testFromX" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_003.phpt b/ext/standard/tests/class_object/get_class_methods_basic_003.phpt new file mode 100644 index 0000000..b64f702 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_003.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test behaviour with interfaces. + */ + +interface I { + public function pubI(); + +} + +class C implements I { + public function pubI() {} + + private function privC() {} + protected function protC() {} + public function pubC() {} + + public static function testFromC() { + echo "Accessing I from C:\n"; + var_dump(get_class_methods("I")); + echo "Accessing C from C:\n"; + var_dump(get_class_methods("C")); + } +} + + +echo "Accessing I from global scope:\n"; +var_dump(get_class_methods("I")); +echo "Accessing C from global scope:\n"; +var_dump(get_class_methods("C")); +C::testFromC(); +echo "Done"; +?> +--EXPECTF-- +Accessing I from global scope: +array(1) { + [0]=> + string(4) "pubI" +} +Accessing C from global scope: +array(3) { + [0]=> + string(4) "pubI" + [1]=> + string(4) "pubC" + [2]=> + string(9) "testFromC" +} +Accessing I from C: +array(1) { + [0]=> + string(4) "pubI" +} +Accessing C from C: +array(5) { + [0]=> + string(4) "pubI" + [1]=> + string(5) "privC" + [2]=> + string(5) "protC" + [3]=> + string(4) "pubC" + [4]=> + string(9) "testFromC" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_error_001.phpt b/ext/standard/tests/class_object/get_class_methods_error_001.phpt new file mode 100644 index 0000000..e606ab6 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_error_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test get_class_methods() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test wrong number of arguments. + */ + +echo "*** Testing get_class_methods() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing get_class_methods() function with Zero arguments --\n"; +var_dump( get_class_methods() ); + +//Test get_class_methods with one more than the expected number of arguments +echo "\n-- Testing get_class_methods() function with more than expected no. of arguments --\n"; +$class = 1; +$extra_arg = 10; +var_dump( get_class_methods($class, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : error conditions *** + +-- Testing get_class_methods() function with Zero arguments -- + +Warning: get_class_methods() expects exactly 1 parameter, 0 given in %s on line 16 +NULL + +-- Testing get_class_methods() function with more than expected no. of arguments -- + +Warning: get_class_methods() expects exactly 1 parameter, 2 given in %s on line 22 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_variation_001.phpt b/ext/standard/tests/class_object/get_class_methods_variation_001.phpt new file mode 100644 index 0000000..8cdef12 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_001.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test get_class_methods() function : usage variations - unexpected types +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing get_class_methods() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( get_class_methods($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +NULL + +Arg value 1 +NULL + +Arg value 12345 +NULL + +Arg value -2345 +NULL + +Arg value 10.5 +NULL + +Arg value -10.5 +NULL + +Arg value 101234567000 +NULL + +Arg value 1.07654321E-9 +NULL + +Arg value 0.5 +NULL +Error: 8 - Array to string conversion, %sget_class_methods_variation_001.php(%d) + +Arg value Array +NULL +Error: 8 - Array to string conversion, %sget_class_methods_variation_001.php(%d) + +Arg value Array +NULL +Error: 8 - Array to string conversion, %sget_class_methods_variation_001.php(%d) + +Arg value Array +NULL +Error: 8 - Array to string conversion, %sget_class_methods_variation_001.php(%d) + +Arg value Array +NULL +Error: 8 - Array to string conversion, %sget_class_methods_variation_001.php(%d) + +Arg value Array +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value 1 +NULL + +Arg value +NULL + +Arg value 1 +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value string +NULL + +Arg value string +NULL +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +array(0) { +} + +Arg value +NULL + +Arg value +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_variation_002.phpt b/ext/standard/tests/class_object/get_class_methods_variation_002.phpt new file mode 100644 index 0000000..60b944c --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_class_methods() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_methods() : usage variations ***\n"; + +class caseSensitivityTest { + function MyMeThOd() {} +} + +var_dump( get_class_methods('CasesensitivitytesT') ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : usage variations *** +array(1) { + [0]=> + string(8) "MyMeThOd" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_variation_001.phpt b/ext/standard/tests/class_object/get_class_variation_001.phpt new file mode 100644 index 0000000..2baef2e --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_001.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test get_class() function : usage variations - passing unexpected types. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class() : usage variations ***\n"; + +// Note: basic use cases in Zend/tests/009.phpt + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo @"\nArg value: $value (type: " . gettype($value) . ")\n"; + var_dump( get_class($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class() : usage variations *** + +Notice: Undefined variable: undefined_var in %sget_class_variation_001.php on line 58 + +Notice: Undefined variable: unset_var in %sget_class_variation_001.php on line 61 + +Arg value: 0 (type: integer) + +Warning: get_class() expects parameter 1 to be object, integer given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 1 (type: integer) + +Warning: get_class() expects parameter 1 to be object, integer given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 12345 (type: integer) + +Warning: get_class() expects parameter 1 to be object, integer given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: -2345 (type: integer) + +Warning: get_class() expects parameter 1 to be object, integer given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 10.5 (type: double) + +Warning: get_class() expects parameter 1 to be object, double given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: -10.5 (type: double) + +Warning: get_class() expects parameter 1 to be object, double given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 101234567000 (type: double) + +Warning: get_class() expects parameter 1 to be object, double given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 1.07654321E-9 (type: double) + +Warning: get_class() expects parameter 1 to be object, double given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 0.5 (type: double) + +Warning: get_class() expects parameter 1 to be object, double given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: Array (type: array) + +Warning: get_class() expects parameter 1 to be object, array given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: Array (type: array) + +Warning: get_class() expects parameter 1 to be object, array given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: Array (type: array) + +Warning: get_class() expects parameter 1 to be object, array given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: Array (type: array) + +Warning: get_class() expects parameter 1 to be object, array given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: Array (type: array) + +Warning: get_class() expects parameter 1 to be object, array given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: NULL) + +Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: NULL) + +Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 1 (type: boolean) + +Warning: get_class() expects parameter 1 to be object, boolean given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: boolean) + +Warning: get_class() expects parameter 1 to be object, boolean given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: 1 (type: boolean) + +Warning: get_class() expects parameter 1 to be object, boolean given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: boolean) + +Warning: get_class() expects parameter 1 to be object, boolean given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: string) + +Warning: get_class() expects parameter 1 to be object, string given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: string) + +Warning: get_class() expects parameter 1 to be object, string given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: string (type: string) + +Warning: get_class() expects parameter 1 to be object, string given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: string (type: string) + +Warning: get_class() expects parameter 1 to be object, string given in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: NULL) + +Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +bool(false) + +Arg value: (type: NULL) + +Warning: get_class() called without object from outside a class in %sget_class_variation_001.php on line %d +bool(false) +Done diff --git a/ext/standard/tests/class_object/get_class_variation_002.phpt b/ext/standard/tests/class_object/get_class_variation_002.phpt new file mode 100644 index 0000000..1ee3529 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_002.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test get_class() function : usage variations - ensure class name case is preserved. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class caseSensitivityTest {} +var_dump(get_class(new casesensitivitytest)); + +echo "Done"; +?> +--EXPECTF-- +string(19) "caseSensitivityTest" +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_vars_error.phpt b/ext/standard/tests/class_object/get_class_vars_error.phpt new file mode 100644 index 0000000..0399e60 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test get_class_vars() function : error conditions +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_vars() : error conditions ***\n"; + + +//Test get_class_vars with one more than the expected number of arguments +echo "\n-- Testing get_class_vars() function with more than expected no. of arguments --\n"; +$obj = new stdclass(); +$extra_arg = 10; +var_dump(get_class_vars($obj,$extra_arg) ); + +// Testing get_class_vars with one less than the expected number of arguments +echo "\n-- Testing get_class_vars() function with less than expected no. of arguments --\n"; +var_dump(get_class_vars()); + +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : error conditions *** + +-- Testing get_class_vars() function with more than expected no. of arguments -- + +Warning: get_class_vars() expects exactly 1 parameter, 2 given in %sget_class_vars_error.php on line %d +NULL + +-- Testing get_class_vars() function with less than expected no. of arguments -- + +Warning: get_class_vars() expects exactly 1 parameter, 0 given in %sget_class_vars_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_vars_variation1.phpt b/ext/standard/tests/class_object/get_class_vars_variation1.phpt new file mode 100644 index 0000000..649e9ae --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_variation1.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test get_class_vars() function : usage variation +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_vars() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for method_name + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( get_class_vars($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--int indexed array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--associative array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--nested arrays-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--instance of classWithToString-- +bool(false) + +--instance of classWithoutToString-- + +Warning: get_class_vars() expects parameter 1 to be string, object given in %sget_class_vars_variation1.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE=== diff --git a/ext/standard/tests/class_object/get_class_vars_variation2.phpt b/ext/standard/tests/class_object/get_class_vars_variation2.phpt new file mode 100644 index 0000000..fad5716 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_variation2.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test get_class_vars() function : testing visibility +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class Ancestor { + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +class Tester extends Ancestor { + public $pub = "public var"; + protected $prot = "protected var"; + private $priv = "private var"; + + static public $pubs = "public static var"; + static protected $prots = "protected static var"; + static private $privs = "private static var"; + + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +class Child extends Tester { + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +echo "*** Testing get_class_vars() : testing visibility\n"; + +echo "\n-- From global context --\n"; +var_dump(get_class_vars("Tester")); + +echo "\n-- From inside an object instance --\n"; +$instance = new Tester(); +$instance->test(); + +echo "\n-- From a static context --\n"; +Tester::testStatic(); + + +echo "\n-- From inside an parent object instance --\n"; +$parent = new Ancestor(); +$parent->test(); + +echo "\n-- From a parents static context --\n"; +Ancestor::testStatic(); + + +echo "\n-- From inside a child object instance --\n"; +$child = new Child(); +$child->test(); + +echo "\n-- From a child's static context --\n"; +Child::testStatic(); +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : testing visibility + +-- From global context -- +array(2) { + ["pub"]=> + string(10) "public var" + ["pubs"]=> + string(17) "public static var" +} + +-- From inside an object instance -- +array(6) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["priv"]=> + string(11) "private var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" + ["privs"]=> + string(18) "private static var" +} + +-- From a static context -- +array(6) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["priv"]=> + string(11) "private var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" + ["privs"]=> + string(18) "private static var" +} + +-- From inside an parent object instance -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From a parents static context -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From inside a child object instance -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From a child's static context -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} +===DONE=== diff --git a/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt b/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt new file mode 100644 index 0000000..123e977 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test get_declared_classes() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_classes() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing get_declared_classes() function with Zero arguments --\n"; +var_dump(get_declared_classes()); + +foreach (get_declared_classes() as $class) { + if (!class_exists($class)) { + echo "Error: $class is not a valid class.\n"; + } +} + +echo "\n-- Ensure userspace classes are listed --\n"; +Class C {} +var_dump(in_array('C', get_declared_classes())); + +echo "\n-- Ensure userspace interfaces are not listed --\n"; +Interface I {} +var_dump(in_array( 'I', get_declared_classes())); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_classes() : basic functionality *** + +-- Testing get_declared_classes() function with Zero arguments -- +array(%d) { +%a +} + +-- Ensure userspace classes are listed -- +bool(true) + +-- Ensure userspace interfaces are not listed -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_classes_error_001.phpt b/ext/standard/tests/class_object/get_declared_classes_error_001.phpt new file mode 100644 index 0000000..d5b40be --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_declared_classes() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_declared_classes() : error conditions ***\n"; + +// One argument +echo "\n-- Testing get_declared_classes() function with one argument --\n"; +$extra_arg = 10;; +var_dump( get_declared_classes($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_classes() : error conditions *** + +-- Testing get_declared_classes() function with one argument -- + +Warning: get_declared_classes() expects exactly 0 parameters, 1 given in %s on line 13 +NULL +Done diff --git a/ext/standard/tests/class_object/get_declared_classes_variation1.phpt b/ext/standard/tests/class_object/get_declared_classes_variation1.phpt new file mode 100644 index 0000000..259f5dc --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_declared_classes() function : testing autoloaded classes +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_classes() : testing autoloaded classes ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- before instance is declared --\n"; +var_dump(in_array('AutoLoaded', get_declared_classes())); + +echo "\n-- after instance is declared --\n"; +$class = new AutoLoaded(); +var_dump(in_array('AutoLoaded', get_declared_classes())); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing get_declared_classes() : testing autoloaded classes *** + +-- before instance is declared -- +bool(false) + +-- after instance is declared -- +bool(true) + +DONE diff --git a/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt b/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt new file mode 100644 index 0000000..a0ec715 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test get_declared_interfaces() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_interfaces() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing get_declared_interfaces() function with Zero arguments --\n"; +var_dump(get_declared_interfaces()); + +foreach (get_declared_interfaces() as $interface) { + if (!interface_exists($interface)) { + echo "Error: $interface is not a valid interface.\n"; + } +} + +echo "\n-- Ensure userspace classes are not listed --\n"; +Class C {} +var_dump(in_array('C', get_declared_interfaces())); + +echo "\n-- Ensure userspace interfaces are listed --\n"; +Interface I {} +var_dump(in_array('I', get_declared_interfaces())); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : basic functionality *** + +-- Testing get_declared_interfaces() function with Zero arguments -- +array(%d) { +%a +} + +-- Ensure userspace classes are not listed -- +bool(false) + +-- Ensure userspace interfaces are listed -- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt b/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt new file mode 100644 index 0000000..2a7f308 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_declared_interfaces() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_declared_interfaces() : error conditions ***\n"; + +// One argument +echo "\n-- Testing get_declared_interfaces() function with one argument --\n"; +$extra_arg = 10;; +var_dump( get_declared_interfaces($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : error conditions *** + +-- Testing get_declared_interfaces() function with one argument -- + +Warning: get_declared_interfaces() expects exactly 0 parameters, 1 given in %s on line 13 +NULL +Done diff --git a/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt b/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt new file mode 100644 index 0000000..56e6161 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_declared_interfaces() function : autoloading of interfaces +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_interfaces() : autoloading of interfaces ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- before interface is used --\n"; +var_dump(in_array('AutoInterface', get_declared_interfaces())); + + +echo "\n-- after interface is used --\n"; +class Implementor implements AutoInterface {} +var_dump(in_array('AutoInterface', get_declared_interfaces())); + +echo "\nDONE\n"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : autoloading of interfaces *** + +-- before interface is used -- +bool(false) + +-- after interface is used -- +bool(true) + +DONE diff --git a/ext/standard/tests/class_object/get_declared_traits_basic_001.phpt b/ext/standard/tests/class_object/get_declared_traits_basic_001.phpt new file mode 100644 index 0000000..69d8de9 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_traits_basic_001.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test get_declared_traits() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_declared_traits() + * Description: Returns an array of all declared traits. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_traits() : basic functionality ***\n"; + +trait MyTrait {} + +// Zero arguments +echo "\n-- Testing get_declared_traits() function with Zero arguments --\n"; +var_dump(get_declared_traits()); + +foreach (get_declared_traits() as $trait) { + if (!trait_exists($trait)) { + echo "Error: $trait is not a valid trait.\n"; + } +} + +echo "\n-- Ensure trait is listed --\n"; +var_dump(in_array('MyTrait', get_declared_traits())); + +echo "\n-- Ensure userspace interfaces are not listed --\n"; +interface I {} +var_dump(in_array( 'I', get_declared_traits())); + +echo "\n-- Ensure userspace classes are not listed --\n"; +class MyClass {} +var_dump(in_array( 'MyClass', get_declared_traits())); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_traits() : basic functionality *** + +-- Testing get_declared_traits() function with Zero arguments -- +array(%d) { +%a +} + +-- Ensure trait is listed -- +bool(true) + +-- Ensure userspace interfaces are not listed -- +bool(false) + +-- Ensure userspace classes are not listed -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_traits_error_001.phpt b/ext/standard/tests/class_object/get_declared_traits_error_001.phpt new file mode 100644 index 0000000..f7a00da --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_traits_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_declared_traits() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_declared_traits() + * Description: Returns an array of all declared traits. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_declared_traits() : error conditions ***\n"; + +// One argument +echo "\n-- Testing get_declared_traits() function with one argument --\n"; +$extra_arg = 10;; +var_dump( get_declared_traits($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_traits() : error conditions *** + +-- Testing get_declared_traits() function with one argument -- + +Warning: get_declared_traits() expects exactly 0 parameters, 1 given in %s on line 13 +NULL +Done diff --git a/ext/standard/tests/class_object/get_declared_traits_variation1.phpt b/ext/standard/tests/class_object/get_declared_traits_variation1.phpt new file mode 100644 index 0000000..bedd37a --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_traits_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test get_declared_traits() function : testing autoloaded traits +--FILE-- +<?php +/* Prototype : proto array get_declared_traits() + * Description: Returns an array of all declared traits. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_traits() : testing autoloaded traits ***\n"; + +function __autoload($trait_name) { + require_once $trait_name . '.inc'; +} + +echo "\n-- before instance is declared --\n"; +var_dump(in_array('AutoTrait', get_declared_traits())); + +echo "\n-- after use is declared --\n"; + +class MyClass { + use AutoTrait; +} + +var_dump(in_array('AutoTrait', get_declared_traits())); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing get_declared_traits() : testing autoloaded traits *** + +-- before instance is declared -- +bool(false) + +-- after use is declared -- +bool(true) + +DONE diff --git a/ext/standard/tests/class_object/get_object_vars_basic_001.phpt b/ext/standard/tests/class_object/get_object_vars_basic_001.phpt new file mode 100644 index 0000000..38ed74f --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_basic_001.phpt @@ -0,0 +1,107 @@ +--TEST-- +get_object_vars(): visibility from static methods (target object passed as arg) +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + private $hiddenPriv = 'A::hiddenPriv'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class B extends A { + private $hiddenPriv = 'B::hiddenPriv'; + private $priv = 'B::priv'; + protected $prot = 'B::prot'; + public $pub = 'B::pub'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class C extends B { + private $hiddenPriv = 'C::hiddenPriv'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class X { + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + + +$b = new B; +echo "\n---( Global scope: )---\n"; +var_dump(get_object_vars($b)); +echo "\n---( Declaring class: )---\n"; +B::test($b); +echo "\n---( Subclass: )---\n"; +C::test($b); +echo "\n---( Superclass: )---\n"; +A::test($b); +echo "\n---( Unrelated class: )---\n"; +X::test($b); +?> +--EXPECTF-- + +---( Global scope: )--- +array(1) { + ["pub"]=> + string(6) "B::pub" +} + +---( Declaring class: )--- +B::test +array(4) { + ["hiddenPriv"]=> + string(13) "B::hiddenPriv" + ["priv"]=> + string(7) "B::priv" + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Subclass: )--- +C::test +array(2) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Superclass: )--- +A::test +array(3) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" + ["hiddenPriv"]=> + string(13) "A::hiddenPriv" +} + +---( Unrelated class: )--- +X::test +array(1) { + ["pub"]=> + string(6) "B::pub" +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_basic_002.phpt b/ext/standard/tests/class_object/get_object_vars_basic_002.phpt new file mode 100644 index 0000000..910926b --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_basic_002.phpt @@ -0,0 +1,64 @@ +--TEST-- +get_object_vars(): visibility from non static methods (target object passed as arg) +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + private $hiddenPriv = 'A::hiddenPriv'; + + public function testA($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class B extends A { + private $hiddenPriv = 'B::hiddenPriv'; + private $priv = 'B::priv'; + protected $prot = 'B::prot'; + public $pub = 'B::pub'; + + public function testB($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + + +$b = new B; +echo "\n---( Declaring class: )---\n"; +$b->testB($b); +echo "\n---( Superclass: )---\n"; +$b->testA($b); + +?> +--EXPECTF-- + +---( Declaring class: )--- +B::testB +array(4) { + ["hiddenPriv"]=> + string(13) "B::hiddenPriv" + ["priv"]=> + string(7) "B::priv" + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Superclass: )--- +A::testA +array(3) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" + ["hiddenPriv"]=> + string(13) "A::hiddenPriv" +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_error_001.phpt b/ext/standard/tests/class_object/get_object_vars_error_001.phpt new file mode 100644 index 0000000..2cb37f4 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_error_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_object_vars() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_object_vars() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing get_object_vars() function with Zero arguments --\n"; +var_dump( get_object_vars() ); + +//Test get_object_vars with one more than the expected number of arguments +echo "\n-- Testing get_object_vars() function with more than expected no. of arguments --\n"; +$obj = new stdclass(); +$extra_arg = 10; +var_dump( get_object_vars($obj, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_object_vars() : error conditions *** + +-- Testing get_object_vars() function with Zero arguments -- + +Warning: get_object_vars() expects exactly 1 parameter, 0 given in %s on line 12 +NULL + +-- Testing get_object_vars() function with more than expected no. of arguments -- + +Warning: get_object_vars() expects exactly 1 parameter, 2 given in %s on line 18 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_001.phpt b/ext/standard/tests/class_object/get_object_vars_variation_001.phpt new file mode 100644 index 0000000..89fbc53 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_001.phpt @@ -0,0 +1,20 @@ +--TEST-- +get_object_vars() - ensure statics are not shown +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + public static $var = 'hello'; +} + +$a = new A; +var_dump(get_object_vars($a)); +?> +--EXPECTF-- +array(0) { +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_002.phpt b/ext/standard/tests/class_object/get_object_vars_variation_002.phpt new file mode 100644 index 0000000..73478de --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_002.phpt @@ -0,0 +1,47 @@ +--TEST-- +get_object_vars() - ensure references are preserved +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +$obj = new stdClass; +var_dump(get_object_vars($obj)); + +$a='original.a'; +$obj->ref = &$a; +$obj->val = $a; + +$arr = get_object_vars($obj); +var_dump($arr); + +$arr['ref'] = 'changed.ref'; +$arr['val'] = 'changed.val'; + +var_dump($arr, $obj, $a); +?> +--EXPECTF-- +array(0) { +} +array(2) { + ["ref"]=> + &string(10) "original.a" + ["val"]=> + string(10) "original.a" +} +array(2) { + ["ref"]=> + &string(11) "changed.ref" + ["val"]=> + string(11) "changed.val" +} +object(stdClass)#1 (2) { + ["ref"]=> + &string(11) "changed.ref" + ["val"]=> + string(10) "original.a" +} +string(11) "changed.ref"
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_003.phpt b/ext/standard/tests/class_object/get_object_vars_variation_003.phpt new file mode 100644 index 0000000..1e68d08 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_003.phpt @@ -0,0 +1,210 @@ +--TEST-- +Test get_object_vars() function : usage variations - unexpected types for argument 1 +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_object_vars() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for obj + +foreach($values as $value) { + echo @"\nArg value $value \n"; + var_dump( get_object_vars($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_object_vars() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 56 + +Notice: Undefined variable: unset_var in %s on line 59 + +Arg value 0 + +Warning: get_object_vars() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Arg value 1 + +Warning: get_object_vars() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Arg value 12345 + +Warning: get_object_vars() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Arg value -2345 + +Warning: get_object_vars() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Arg value 10.5 + +Warning: get_object_vars() expects parameter 1 to be object, double given in %s on line %d +NULL + +Arg value -10.5 + +Warning: get_object_vars() expects parameter 1 to be object, double given in %s on line %d +NULL + +Arg value 101234567000 + +Warning: get_object_vars() expects parameter 1 to be object, double given in %s on line %d +NULL + +Arg value 1.07654321E-9 + +Warning: get_object_vars() expects parameter 1 to be object, double given in %s on line %d +NULL + +Arg value 0.5 + +Warning: get_object_vars() expects parameter 1 to be object, double given in %s on line %d +NULL + +Arg value Array + +Warning: get_object_vars() expects parameter 1 to be object, array given in %s on line %d +NULL + +Arg value Array + +Warning: get_object_vars() expects parameter 1 to be object, array given in %s on line %d +NULL + +Arg value Array + +Warning: get_object_vars() expects parameter 1 to be object, array given in %s on line %d +NULL + +Arg value Array + +Warning: get_object_vars() expects parameter 1 to be object, array given in %s on line %d +NULL + +Arg value Array + +Warning: get_object_vars() expects parameter 1 to be object, array given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, null given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, null given in %s on line %d +NULL + +Arg value 1 + +Warning: get_object_vars() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Arg value 1 + +Warning: get_object_vars() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, string given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, string given in %s on line %d +NULL + +Arg value string + +Warning: get_object_vars() expects parameter 1 to be object, string given in %s on line %d +NULL + +Arg value string + +Warning: get_object_vars() expects parameter 1 to be object, string given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, null given in %s on line %d +NULL + +Arg value + +Warning: get_object_vars() expects parameter 1 to be object, null given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_error_001.phpt b/ext/standard/tests/class_object/get_parent_class_error_001.phpt new file mode 100644 index 0000000..40c3dba --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test get_parent_class() function : error conditions - wrong number of args. +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_parent_class() : error conditions ***\n"; + + +//Test get_parent_class with one more than the expected number of arguments +echo "\n-- Testing get_parent_class() function with more than expected no. of arguments --\n"; +$object = 1; +$extra_arg = 10; +var_dump( get_parent_class($object, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : error conditions *** + +-- Testing get_parent_class() function with more than expected no. of arguments -- + +Warning: get_parent_class() expects at most 1 parameter, 2 given in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_variation_001.phpt b/ext/standard/tests/class_object/get_parent_class_variation_001.phpt new file mode 100644 index 0000000..6f2e328 --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_variation_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_parent_class() function : variation - case sensitivity +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +// Note: basic use cases in Zend/tests/010.phpt + +echo "*** Testing get_parent_class() : variation ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(get_parent_class('CasesensitivitytestCHILD')); +var_dump(get_parent_class(new CasesensitivitytestCHILD)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : variation *** +string(19) "caseSensitivityTest" +string(19) "caseSensitivityTest" +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_variation_002.phpt b/ext/standard/tests/class_object/get_parent_class_variation_002.phpt new file mode 100644 index 0000000..0d19e22 --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_variation_002.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test get_parent_class() function : usage variations - unexpected argument type. +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing get_parent_class() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( get_parent_class($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(68) +Error: 8 - Undefined variable: unset_var, %s(71) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %sget_parent_class_variation_002.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sget_parent_class_variation_002.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sget_parent_class_variation_002.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sget_parent_class_variation_002.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sget_parent_class_variation_002.php(%d) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_error.phpt b/ext/standard/tests/class_object/interface_exists_error.phpt new file mode 100644 index 0000000..bf95a43 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test interface_exists() function : error conditions +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing interface_exists() function with Zero arguments --\n"; +var_dump( interface_exists() ); + +//Test interface_exists with one more than the expected number of arguments +echo "\n-- Testing interface_exists() function with more than expected no. of arguments --\n"; +$classname = 'string_val'; +$autoload = true; +$extra_arg = 10; +var_dump( interface_exists($classname, $autoload, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : error conditions *** + +-- Testing interface_exists() function with Zero arguments -- + +Warning: interface_exists() expects at least 1 parameter, 0 given in %sinterface_exists_error.php on line %d +NULL + +-- Testing interface_exists() function with more than expected no. of arguments -- + +Warning: interface_exists() expects at most 2 parameters, 3 given in %sinterface_exists_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation1.phpt b/ext/standard/tests/class_object/interface_exists_variation1.phpt new file mode 100644 index 0000000..34d0e1e --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation1.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test interface_exists() function : usage variation +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$autoload = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for classname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( interface_exists($value, $autoload) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--int indexed array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--associative array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--nested arrays-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--instance of classWithToString-- +bool(false) + +--instance of classWithoutToString-- + +Warning: interface_exists() expects parameter 1 to be string, object given in %sinterface_exists_variation1.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation2.phpt b/ext/standard/tests/class_object/interface_exists_variation2.phpt new file mode 100644 index 0000000..4137d8a --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation2.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test interface_exists() function : usage variation +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$classname = 'aBogusInterfaceName'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for autoload + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( interface_exists($classname, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--int indexed array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--associative array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--nested arrays-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--string DQ-- +bool(false) + +--string SQ-- +bool(false) + +--mixed case string-- +bool(false) + +--heredoc-- +bool(false) + +--instance of classWithToString-- + +Warning: interface_exists() expects parameter 2 to be boolean, object given in %sinterface_exists_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: interface_exists() expects parameter 2 to be boolean, object given in %sinterface_exists_variation2.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE=== diff --git a/ext/standard/tests/class_object/interface_exists_variation3.phpt b/ext/standard/tests/class_object/interface_exists_variation3.phpt new file mode 100644 index 0000000..d25d74b --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation3.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test interface_exists() function : autoloaded interface +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : autoloaded interface ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- no autoloading --\n"; +var_dump(interface_exists("AutoInterface", false)); + +echo "\n-- with autoloading --\n"; +var_dump(interface_exists("AutoInterface", true)); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing interface_exists() : autoloaded interface *** + +-- no autoloading -- +bool(false) + +-- with autoloading -- +bool(true) + +DONE
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation4.phpt b/ext/standard/tests/class_object/interface_exists_variation4.phpt new file mode 100644 index 0000000..c059805 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation4.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test interface_exists() function : test autoload default value +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : test autoload default value ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + + +var_dump(interface_exists("AutoInterface")); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing interface_exists() : test autoload default value *** +bool(true) + +DONE
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a.phpt b/ext/standard/tests/class_object/is_a.phpt new file mode 100644 index 0000000..832d555 --- /dev/null +++ b/ext/standard/tests/class_object/is_a.phpt @@ -0,0 +1,378 @@ +--TEST-- +is_a and is_subclass_of behaviour (with and without autoload) +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +interface if_a { + function f_a(); +} + +interface if_b extends if_a { + function f_b(); +} + +class base { + function _is_a($sub) { + + echo "\n>>> With Defined class\n"; + echo str_pad('is_a( OBJECT:'.get_class($this).', '.$sub.') = ', 60) . (is_a($this, $sub) ? 'yes' : 'no')."\n"; + echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_a(get_class($this), $sub) ? 'yes' : 'no')."\n"; + echo str_pad('is_a( STRING:'.get_class($this).', '.$sub.', true) = ', 60). (is_a(get_class($this), $sub, true) ? 'yes' : 'no')."\n"; + echo str_pad('is_subclass_of( OBJECT:'.get_class($this).', '.$sub.') = ', 60). (is_subclass_of($this, $sub) ? 'yes' : 'no')."\n"; + echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.') = ', 60). (is_subclass_of(get_class($this), $sub) ? 'yes' : 'no')."\n"; + echo str_pad('is_subclass_of( STRING:'.get_class($this).', '.$sub.',false) = ', 60). (is_subclass_of(get_class($this), $sub , false) ? 'yes' : 'no')."\n"; + + // with autoload options.. + echo ">>> With Undefined\n"; + echo str_pad('is_a( STRING:undefB, '.$sub.',true) = ', 60). (is_a('undefB', $sub, true) ? 'yes' : 'no')."\n"; + echo str_pad('is_a( STRING:undefB, '.$sub.') = ', 60). (is_a('undefB', $sub) ? 'yes' : 'no')."\n"; + echo str_pad('is_subclass_of( STRING:undefB, '.$sub.',false) = ', 60). (is_subclass_of('undefB', $sub, false) ? 'yes' : 'no')."\n"; + echo str_pad('is_subclass_of( STRING:undefB, '.$sub.') = ', 60). (is_subclass_of('undefB', $sub) ? 'yes' : 'no')."\n"; + } + function test() { + echo $this->_is_a('base'); + echo $this->_is_a('derived_a'); + echo $this->_is_a('if_a'); + echo $this->_is_a('undefA'); + echo "\n"; + } +} + +class derived_a extends base implements if_a { + function f_a() {} +} + +class derived_b extends base implements if_a, if_b { + function f_a() {} + function f_b() {} +} + +class derived_c extends derived_a implements if_b { + function f_b() {} +} + +class derived_d extends derived_c { +} + +$t = new base(); +$t->test(); + +$t = new derived_a(); +$t->test(); + +eval(' + function __autoload($name) + { + echo ">>>> In __autoload: "; + var_dump($name); + } +'); + +echo "NOW WITH AUTOLOAD\n\n"; + +$t = new base(); +$t->test(); + +$t = new derived_a(); +$t->test(); + +$t = new derived_b(); +$t->test(); + + + + + +?> +--EXPECTF-- +>>> With Defined class +is_a( OBJECT:base, base) = yes +is_a( STRING:base, base) = no +is_a( STRING:base, base, true) = yes +is_subclass_of( OBJECT:base, base) = no +is_subclass_of( STRING:base, base) = no +is_subclass_of( STRING:base, base,false) = no +>>> With Undefined +is_a( STRING:undefB, base,true) = no +is_a( STRING:undefB, base) = no +is_subclass_of( STRING:undefB, base,false) = no +is_subclass_of( STRING:undefB, base) = no + +>>> With Defined class +is_a( OBJECT:base, derived_a) = no +is_a( STRING:base, derived_a) = no +is_a( STRING:base, derived_a, true) = no +is_subclass_of( OBJECT:base, derived_a) = no +is_subclass_of( STRING:base, derived_a) = no +is_subclass_of( STRING:base, derived_a,false) = no +>>> With Undefined +is_a( STRING:undefB, derived_a,true) = no +is_a( STRING:undefB, derived_a) = no +is_subclass_of( STRING:undefB, derived_a,false) = no +is_subclass_of( STRING:undefB, derived_a) = no + +>>> With Defined class +is_a( OBJECT:base, if_a) = no +is_a( STRING:base, if_a) = no +is_a( STRING:base, if_a, true) = no +is_subclass_of( OBJECT:base, if_a) = no +is_subclass_of( STRING:base, if_a) = no +is_subclass_of( STRING:base, if_a,false) = no +>>> With Undefined +is_a( STRING:undefB, if_a,true) = no +is_a( STRING:undefB, if_a) = no +is_subclass_of( STRING:undefB, if_a,false) = no +is_subclass_of( STRING:undefB, if_a) = no + +>>> With Defined class +is_a( OBJECT:base, undefA) = no +is_a( STRING:base, undefA) = no +is_a( STRING:base, undefA, true) = no +is_subclass_of( OBJECT:base, undefA) = no +is_subclass_of( STRING:base, undefA) = no +is_subclass_of( STRING:base, undefA,false) = no +>>> With Undefined +is_a( STRING:undefB, undefA,true) = no +is_a( STRING:undefB, undefA) = no +is_subclass_of( STRING:undefB, undefA,false) = no +is_subclass_of( STRING:undefB, undefA) = no + + +>>> With Defined class +is_a( OBJECT:derived_a, base) = yes +is_a( STRING:derived_a, base) = no +is_a( STRING:derived_a, base, true) = yes +is_subclass_of( OBJECT:derived_a, base) = yes +is_subclass_of( STRING:derived_a, base) = yes +is_subclass_of( STRING:derived_a, base,false) = no +>>> With Undefined +is_a( STRING:undefB, base,true) = no +is_a( STRING:undefB, base) = no +is_subclass_of( STRING:undefB, base,false) = no +is_subclass_of( STRING:undefB, base) = no + +>>> With Defined class +is_a( OBJECT:derived_a, derived_a) = yes +is_a( STRING:derived_a, derived_a) = no +is_a( STRING:derived_a, derived_a, true) = yes +is_subclass_of( OBJECT:derived_a, derived_a) = no +is_subclass_of( STRING:derived_a, derived_a) = no +is_subclass_of( STRING:derived_a, derived_a,false) = no +>>> With Undefined +is_a( STRING:undefB, derived_a,true) = no +is_a( STRING:undefB, derived_a) = no +is_subclass_of( STRING:undefB, derived_a,false) = no +is_subclass_of( STRING:undefB, derived_a) = no + +>>> With Defined class +is_a( OBJECT:derived_a, if_a) = yes +is_a( STRING:derived_a, if_a) = no +is_a( STRING:derived_a, if_a, true) = yes +is_subclass_of( OBJECT:derived_a, if_a) = yes +is_subclass_of( STRING:derived_a, if_a) = yes +is_subclass_of( STRING:derived_a, if_a,false) = no +>>> With Undefined +is_a( STRING:undefB, if_a,true) = no +is_a( STRING:undefB, if_a) = no +is_subclass_of( STRING:undefB, if_a,false) = no +is_subclass_of( STRING:undefB, if_a) = no + +>>> With Defined class +is_a( OBJECT:derived_a, undefA) = no +is_a( STRING:derived_a, undefA) = no +is_a( STRING:derived_a, undefA, true) = no +is_subclass_of( OBJECT:derived_a, undefA) = no +is_subclass_of( STRING:derived_a, undefA) = no +is_subclass_of( STRING:derived_a, undefA,false) = no +>>> With Undefined +is_a( STRING:undefB, undefA,true) = no +is_a( STRING:undefB, undefA) = no +is_subclass_of( STRING:undefB, undefA,false) = no +is_subclass_of( STRING:undefB, undefA) = no + +NOW WITH AUTOLOAD + + +>>> With Defined class +is_a( OBJECT:base, base) = yes +is_a( STRING:base, base) = no +is_a( STRING:base, base, true) = yes +is_subclass_of( OBJECT:base, base) = no +is_subclass_of( STRING:base, base) = no +is_subclass_of( STRING:base, base,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, base,true) = no +is_a( STRING:undefB, base) = no +is_subclass_of( STRING:undefB, base,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, base) = no + +>>> With Defined class +is_a( OBJECT:base, derived_a) = no +is_a( STRING:base, derived_a) = no +is_a( STRING:base, derived_a, true) = no +is_subclass_of( OBJECT:base, derived_a) = no +is_subclass_of( STRING:base, derived_a) = no +is_subclass_of( STRING:base, derived_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, derived_a,true) = no +is_a( STRING:undefB, derived_a) = no +is_subclass_of( STRING:undefB, derived_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, derived_a) = no + +>>> With Defined class +is_a( OBJECT:base, if_a) = no +is_a( STRING:base, if_a) = no +is_a( STRING:base, if_a, true) = no +is_subclass_of( OBJECT:base, if_a) = no +is_subclass_of( STRING:base, if_a) = no +is_subclass_of( STRING:base, if_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, if_a,true) = no +is_a( STRING:undefB, if_a) = no +is_subclass_of( STRING:undefB, if_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, if_a) = no + +>>> With Defined class +is_a( OBJECT:base, undefA) = no +is_a( STRING:base, undefA) = no +is_a( STRING:base, undefA, true) = no +is_subclass_of( OBJECT:base, undefA) = no +is_subclass_of( STRING:base, undefA) = no +is_subclass_of( STRING:base, undefA,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, undefA,true) = no +is_a( STRING:undefB, undefA) = no +is_subclass_of( STRING:undefB, undefA,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, undefA) = no + + +>>> With Defined class +is_a( OBJECT:derived_a, base) = yes +is_a( STRING:derived_a, base) = no +is_a( STRING:derived_a, base, true) = yes +is_subclass_of( OBJECT:derived_a, base) = yes +is_subclass_of( STRING:derived_a, base) = yes +is_subclass_of( STRING:derived_a, base,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, base,true) = no +is_a( STRING:undefB, base) = no +is_subclass_of( STRING:undefB, base,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, base) = no + +>>> With Defined class +is_a( OBJECT:derived_a, derived_a) = yes +is_a( STRING:derived_a, derived_a) = no +is_a( STRING:derived_a, derived_a, true) = yes +is_subclass_of( OBJECT:derived_a, derived_a) = no +is_subclass_of( STRING:derived_a, derived_a) = no +is_subclass_of( STRING:derived_a, derived_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, derived_a,true) = no +is_a( STRING:undefB, derived_a) = no +is_subclass_of( STRING:undefB, derived_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, derived_a) = no + +>>> With Defined class +is_a( OBJECT:derived_a, if_a) = yes +is_a( STRING:derived_a, if_a) = no +is_a( STRING:derived_a, if_a, true) = yes +is_subclass_of( OBJECT:derived_a, if_a) = yes +is_subclass_of( STRING:derived_a, if_a) = yes +is_subclass_of( STRING:derived_a, if_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, if_a,true) = no +is_a( STRING:undefB, if_a) = no +is_subclass_of( STRING:undefB, if_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, if_a) = no + +>>> With Defined class +is_a( OBJECT:derived_a, undefA) = no +is_a( STRING:derived_a, undefA) = no +is_a( STRING:derived_a, undefA, true) = no +is_subclass_of( OBJECT:derived_a, undefA) = no +is_subclass_of( STRING:derived_a, undefA) = no +is_subclass_of( STRING:derived_a, undefA,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, undefA,true) = no +is_a( STRING:undefB, undefA) = no +is_subclass_of( STRING:undefB, undefA,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, undefA) = no + + +>>> With Defined class +is_a( OBJECT:derived_b, base) = yes +is_a( STRING:derived_b, base) = no +is_a( STRING:derived_b, base, true) = yes +is_subclass_of( OBJECT:derived_b, base) = yes +is_subclass_of( STRING:derived_b, base) = yes +is_subclass_of( STRING:derived_b, base,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, base,true) = no +is_a( STRING:undefB, base) = no +is_subclass_of( STRING:undefB, base,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, base) = no + +>>> With Defined class +is_a( OBJECT:derived_b, derived_a) = no +is_a( STRING:derived_b, derived_a) = no +is_a( STRING:derived_b, derived_a, true) = no +is_subclass_of( OBJECT:derived_b, derived_a) = no +is_subclass_of( STRING:derived_b, derived_a) = no +is_subclass_of( STRING:derived_b, derived_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, derived_a,true) = no +is_a( STRING:undefB, derived_a) = no +is_subclass_of( STRING:undefB, derived_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, derived_a) = no + +>>> With Defined class +is_a( OBJECT:derived_b, if_a) = yes +is_a( STRING:derived_b, if_a) = no +is_a( STRING:derived_b, if_a, true) = yes +is_subclass_of( OBJECT:derived_b, if_a) = yes +is_subclass_of( STRING:derived_b, if_a) = yes +is_subclass_of( STRING:derived_b, if_a,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, if_a,true) = no +is_a( STRING:undefB, if_a) = no +is_subclass_of( STRING:undefB, if_a,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, if_a) = no + +>>> With Defined class +is_a( OBJECT:derived_b, undefA) = no +is_a( STRING:derived_b, undefA) = no +is_a( STRING:derived_b, undefA, true) = no +is_subclass_of( OBJECT:derived_b, undefA) = no +is_subclass_of( STRING:derived_b, undefA) = no +is_subclass_of( STRING:derived_b, undefA,false) = no +>>> With Undefined +>>>> In __autoload: string(6) "undefB" +is_a( STRING:undefB, undefA,true) = no +is_a( STRING:undefB, undefA) = no +is_subclass_of( STRING:undefB, undefA,false) = no +>>>> In __autoload: string(6) "undefB" +is_subclass_of( STRING:undefB, undefA) = no diff --git a/ext/standard/tests/class_object/is_a_error_001.phpt b/ext/standard/tests/class_object/is_a_error_001.phpt new file mode 100644 index 0000000..6518a03 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_error_001.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test is_a() function : error conditions - wrong number of args +--INI-- +error_reporting=E_ALL | E_STRICT | E_DEPRECATED +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name, bool allow_string) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_a() : error conditions ***\n"; + +//Test is_a with one more than the expected number of arguments +echo "\n-- Testing is_a() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$class_name = 'string_val'; +$allow_string = false; +$extra_arg = 10; + +var_dump( is_a($object, $class_name, $allow_string, $object) ); + +//Test is_a with one more than the expected number of arguments +echo "\n-- Testing is_a() function with non-boolean in last position --\n"; +var_dump( is_a($object, $class_name, $object) ); + + +// Testing is_a with one less than the expected number of arguments +echo "\n-- Testing is_a() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( is_a($object) ); + +echo "Done"; +?> +--EXPECTF-- + +*** Testing is_a() : error conditions *** + +-- Testing is_a() function with more than expected no. of arguments -- + +Warning: is_a() expects at most 3 parameters, 4 given in %s on line 17 +NULL + +-- Testing is_a() function with non-boolean in last position -- + +Warning: is_a() expects parameter 3 to be boolean, object given in %s on line 21 +NULL + +-- Testing is_a() function with less than expected no. of arguments -- + +Warning: is_a() expects at least 2 parameters, 1 given in %s on line 27 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a_variation_001.phpt b/ext/standard/tests/class_object/is_a_variation_001.phpt new file mode 100644 index 0000000..d449fd3 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_001.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test is_a() function : usage variations - wrong type for arg 1 +--INI-- +error_reporting=E_ALL | E_STRICT | E_DEPRECATED +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +echo "*** Testing is_a() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'stdClass'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo @"\nArg value $value \n"; + var_dump( is_a($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 59 + +Notice: Undefined variable: unset_var in %s on line 62 + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +bool(false) + +Arg value String +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done diff --git a/ext/standard/tests/class_object/is_a_variation_002.phpt b/ext/standard/tests/class_object/is_a_variation_002.phpt new file mode 100644 index 0000000..a34c325 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_002.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test is_a() function : usage variations - wrong type for arg 2 +--INI-- +error_reporting=E_ALL | E_STRICT | E_DEPRECATED +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class C { + function __toString() { + return "C Instance"; + } +} + +echo "*** Testing is_a() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new C, + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class_name + +foreach($values as $value) { + echo @"\nArg value $value \n"; + var_dump( is_a($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 64 + +Notice: Undefined variable: unset_var in %s on line 67 + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array + +Warning: is_a() expects parameter 2 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: is_a() expects parameter 2 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: is_a() expects parameter 2 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: is_a() expects parameter 2 to be string, array given in %s on line %d +NULL + +Arg value Array + +Warning: is_a() expects parameter 2 to be string, array given in %s on line %d +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value C Instance +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done diff --git a/ext/standard/tests/class_object/is_a_variation_003.phpt b/ext/standard/tests/class_object/is_a_variation_003.phpt new file mode 100644 index 0000000..1258647 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_003.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test is_a() function : usage variations - case sensitivity +--INI-- +error_reporting=E_ALL | E_STRICT | E_DEPRECATED +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_a() : usage variations ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(is_a(new caseSensitivityTestChild, 'caseSensitivityTEST')); + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** +bool(true) +Done diff --git a/ext/standard/tests/class_object/is_subclass_of_error_001.phpt b/ext/standard/tests/class_object/is_subclass_of_error_001.phpt new file mode 100644 index 0000000..987dcd4 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_error_001.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test is_subclass_of() function : wrong number of args +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_subclass_of() : error conditions ***\n"; + + +//Test is_subclass_of with one more than the expected number of arguments +echo "\n-- Testing is_subclass_of() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$class_name = 'string_val'; +$allow_string = false; +$extra_arg = 10; +var_dump( is_subclass_of($object, $class_name, $allow_string, $extra_arg) ); + +//Test is_subclass_of with invalid last argument +echo "\n-- Testing is_subclass_of() function with more than typo style invalid 3rd argument --\n"; +var_dump( is_subclass_of($object, $class_name, $class_name) ); + + +//Test is_subclass_of with invalid last argument +echo "\n-- Testing is_subclass_of() function with more than invalid 3rd argument --\n"; +var_dump( is_subclass_of($object, $class_name, $object) ); + +// Testing is_subclass_of with one less than the expected number of arguments +echo "\n-- Testing is_subclass_of() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( is_subclass_of($object) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : error conditions *** + +-- Testing is_subclass_of() function with more than expected no. of arguments -- + +Warning: is_subclass_of() expects at most 3 parameters, 4 given in %s on line 17 +NULL + +-- Testing is_subclass_of() function with more than typo style invalid 3rd argument -- +bool(false) + +-- Testing is_subclass_of() function with more than invalid 3rd argument -- + +Warning: is_subclass_of() expects parameter 3 to be boolean, object given in %s on line 26 +NULL + +-- Testing is_subclass_of() function with less than expected no. of arguments -- + +Warning: is_subclass_of() expects at least 2 parameters, 1 given in %s on line 31 +NULL +Done diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt new file mode 100644 index 0000000..201d878 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt @@ -0,0 +1,176 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(69) +Error: 8 - Undefined variable: unset_var, %s(72) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_001.php(%d) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt new file mode 100644 index 0000000..9bb712b --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt @@ -0,0 +1,176 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class_name + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_002.php(%d) + +Arg value Array +Error: 2 - is_subclass_of() expects parameter 2 to be string, array given, %s(%d) +NULL +Error: 8 - Array to string conversion, %sis_subclass_of_variation_002.php(%d) + +Arg value Array +Error: 2 - is_subclass_of() expects parameter 2 to be string, array given, %s(%d) +NULL +Error: 8 - Array to string conversion, %sis_subclass_of_variation_002.php(%d) + +Arg value Array +Error: 2 - is_subclass_of() expects parameter 2 to be string, array given, %s(%d) +NULL +Error: 8 - Array to string conversion, %sis_subclass_of_variation_002.php(%d) + +Arg value Array +Error: 2 - is_subclass_of() expects parameter 2 to be string, array given, %s(%d) +NULL +Error: 8 - Array to string conversion, %sis_subclass_of_variation_002.php(%d) + +Arg value Array +Error: 2 - is_subclass_of() expects parameter 2 to be string, array given, %s(%d) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(%d) + +Arg value +Error: 2 - is_subclass_of() expects parameter 2 to be string, object given, %s(%d) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt new file mode 100644 index 0000000..d4aef12 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test is_subclass_of() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +echo "*** Testing is_a() : usage variations ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(is_subclass_of('caseSensitivityTestCHILD', 'caseSensitivityTEST')); + +echo "Done" +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +*** Testing is_a() : usage variations *** +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt new file mode 100644 index 0000000..65ae8a4 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt @@ -0,0 +1,176 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 1 with valid class in arg 2. +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'stdClass'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(69) +Error: 8 - Undefined variable: unset_var, %s(72) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_004.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_004.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_004.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_004.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %sis_subclass_of_variation_004.php(%d) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_001.phpt b/ext/standard/tests/class_object/method_exists_basic_001.phpt new file mode 100644 index 0000000..2f11e4c --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_001.phpt @@ -0,0 +1,83 @@ +--TEST-- +method_exists() on userspace classes; static & non-static methods with various visibilities. +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class B { + public function inherit_pub() {} + protected function inherit_prot() {} + private function inherit_priv() {} + static public function inherit_static_pub() {} + static protected function inherit_static_prot() {} + static private function inherit_static_priv() {} +} + +Class C extends B { + public function pub() {} + protected function prot() {} + private function priv() {} + static public function static_pub() {} + static protected function static_prot() {} + static private function static_priv() {} +} + + +$methods = array( + 'inherit_pub', 'inherit_prot', 'inherit_priv', + 'inherit_static_pub', 'inherit_static_prot', 'inherit_static_priv', + 'pub', 'prot', 'priv', + 'static_pub', 'static_prot', 'static_priv', + 'non_existent'); + +echo "\n ---(Using string class name)---\n"; +foreach ($methods as $method) { + echo "Does C::$method exist? "; + var_dump(method_exists("C", $method)); +} + +echo "\n ---(Using object)---\n"; +$myC = new C; +foreach ($methods as $method) { + echo "Does C::$method exist? "; + var_dump(method_exists($myC, $method)); +} + +echo "Done"; +?> +--EXPECTF-- + + ---(Using string class name)--- +Does C::inherit_pub exist? bool(true) +Does C::inherit_prot exist? bool(true) +Does C::inherit_priv exist? bool(true) +Does C::inherit_static_pub exist? bool(true) +Does C::inherit_static_prot exist? bool(true) +Does C::inherit_static_priv exist? bool(true) +Does C::pub exist? bool(true) +Does C::prot exist? bool(true) +Does C::priv exist? bool(true) +Does C::static_pub exist? bool(true) +Does C::static_prot exist? bool(true) +Does C::static_priv exist? bool(true) +Does C::non_existent exist? bool(false) + + ---(Using object)--- +Does C::inherit_pub exist? bool(true) +Does C::inherit_prot exist? bool(true) +Does C::inherit_priv exist? bool(true) +Does C::inherit_static_pub exist? bool(true) +Does C::inherit_static_prot exist? bool(true) +Does C::inherit_static_priv exist? bool(true) +Does C::pub exist? bool(true) +Does C::prot exist? bool(true) +Does C::priv exist? bool(true) +Does C::static_pub exist? bool(true) +Does C::static_prot exist? bool(true) +Does C::static_priv exist? bool(true) +Does C::non_existent exist? bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_002.phpt b/ext/standard/tests/class_object/method_exists_basic_002.phpt new file mode 100644 index 0000000..f6b62aa --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_002.phpt @@ -0,0 +1,33 @@ +--TEST-- +method_exists() on internal classes +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo " ---(Internal classes, using string class name)---\n"; +echo "Does exception::getmessage exist? "; +var_dump(method_exists("exception", "getmessage")); +echo "Does stdclass::nonexistent exist? "; +var_dump(method_exists("stdclass", "nonexistent")); + +echo "\n ---(Internal classes, using class instance)---\n"; +echo "Does exception::getmessage exist? "; +var_dump(method_exists(new exception, "getmessage")); +echo "Does stdclass::nonexistent exist? "; +var_dump(method_exists(new stdclass, "nonexistent")); + +echo "Done"; +?> +--EXPECTF-- + ---(Internal classes, using string class name)--- +Does exception::getmessage exist? bool(true) +Does stdclass::nonexistent exist? bool(false) + + ---(Internal classes, using class instance)--- +Does exception::getmessage exist? bool(true) +Does stdclass::nonexistent exist? bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_003.phpt b/ext/standard/tests/class_object/method_exists_basic_003.phpt new file mode 100644 index 0000000..32f62b7 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_003.phpt @@ -0,0 +1,22 @@ +--TEST-- +method_exists() on non-existent class, with __autoload(). +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($name) { + echo "In __autoload($name)\n"; +} + +var_dump(method_exists('UndefC', 'func')); + +echo "Done"; +?> +--EXPECTF-- +In __autoload(UndefC) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_error_001.phpt b/ext/standard/tests/class_object/method_exists_error_001.phpt new file mode 100644 index 0000000..929d84a --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_error_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test method_exists() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing method_exists() : error conditions ***\n"; + + +//Test method_exists with one more than the expected number of arguments +echo "\n-- Testing method_exists() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$method = 'string_val'; +$extra_arg = 10; +var_dump( method_exists($object, $method, $extra_arg) ); + +// Testing method_exists with one less than the expected number of arguments +echo "\n-- Testing method_exists() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( method_exists($object) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : error conditions *** + +-- Testing method_exists() function with more than expected no. of arguments -- + +Warning: method_exists() expects exactly 2 parameters, 3 given in %s on line 16 +NULL + +-- Testing method_exists() function with less than expected no. of arguments -- + +Warning: method_exists() expects exactly 2 parameters, 1 given in %s on line 21 +NULL +Done diff --git a/ext/standard/tests/class_object/method_exists_variation_001.phpt b/ext/standard/tests/class_object/method_exists_variation_001.phpt new file mode 100644 index 0000000..1947c76 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_001.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test method_exists() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing method_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$method = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( method_exists($value, $method) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(68) +Error: 8 - Undefined variable: unset_var, %s(71) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_001.php(%d) + +Arg value Array +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_001.php(%d) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_variation_002.phpt b/ext/standard/tests/class_object/method_exists_variation_002.phpt new file mode 100644 index 0000000..b1204e8 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_002.phpt @@ -0,0 +1,176 @@ +--TEST-- +Test method_exists() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing method_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for method + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( method_exists($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) +Error: 8 - Array to string conversion, %smethod_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - method_exists() expects parameter 2 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %smethod_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - method_exists() expects parameter 2 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %smethod_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - method_exists() expects parameter 2 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %smethod_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - method_exists() expects parameter 2 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %smethod_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - method_exists() expects parameter 2 to be string, array given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 2 - method_exists() expects parameter 2 to be string, object given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_variation_003.phpt b/ext/standard/tests/class_object/method_exists_variation_003.phpt new file mode 100644 index 0000000..debe5a3 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_003.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test method_exists() function : variation - Case sensitivity +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing method_exists() : variation ***\n"; + +Class caseSensitivityTest { + public function myMethod() {} +} + +var_dump(method_exists(new casesensitivitytest, 'myMetHOD')); +var_dump(method_exists('casesensiTivitytest', 'myMetHOD')); + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : variation *** +bool(true) +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/property_exists_error.phpt b/ext/standard/tests/class_object/property_exists_error.phpt new file mode 100644 index 0000000..e40e08b --- /dev/null +++ b/ext/standard/tests/class_object/property_exists_error.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test property_exists() function : error conditions +--FILE-- +<?php +/* Prototype : bool property_exists(mixed object_or_class, string property_name) + * Description: Checks if the object or class has a property + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing property_exists() : error conditions ***\n"; + +$object_or_class = "obj"; +$property_name = 'string_val'; +$extra_arg = 10; + + +echo "\n-- Testing property_exists() function with more than expected no. of arguments --\n"; +var_dump( property_exists($object_or_class, $property_name, $extra_arg) ); + + +echo "\n-- Testing property_exists() function with less than expected no. of arguments --\n"; +var_dump( property_exists($object_or_class) ); + +echo "\n-- Testing property_exists() function with incorrect arguments --\n"; +var_dump( property_exists(10, $property_name) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing property_exists() : error conditions *** + +-- Testing property_exists() function with more than expected no. of arguments -- + +Warning: property_exists() expects exactly 2 parameters, 3 given in %sproperty_exists_error.php on line %d +NULL + +-- Testing property_exists() function with less than expected no. of arguments -- + +Warning: property_exists() expects exactly 2 parameters, 1 given in %sproperty_exists_error.php on line %d +NULL + +-- Testing property_exists() function with incorrect arguments -- + +Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/property_exists_variation1.phpt b/ext/standard/tests/class_object/property_exists_variation1.phpt new file mode 100644 index 0000000..1505a4b --- /dev/null +++ b/ext/standard/tests/class_object/property_exists_variation1.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test property_exists() function : class auto loading +--FILE-- +<?php +/* Prototype : bool property_exists(mixed object_or_class, string property_name) + * Description: Checks if the object or class has a property + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing property_exists() : class auto loading ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\ntesting property in autoloaded class\n"; +var_dump(property_exists("AutoTest", "bob")); + +echo "\ntesting __get magic method\n"; +var_dump(property_exists("AutoTest", "foo")); + +?> +===DONE=== +--EXPECTF-- +*** Testing property_exists() : class auto loading *** + +testing property in autoloaded class +bool(true) + +testing __get magic method +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/trait_class_exists_variation_003.phpt b/ext/standard/tests/class_object/trait_class_exists_variation_003.phpt new file mode 100644 index 0000000..6a8e55b --- /dev/null +++ b/ext/standard/tests/class_object/trait_class_exists_variation_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test trait_exists() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) + * Description: Checks if the trait exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +trait caseSensitivityTest {} +var_dump(trait_exists('casesensitivitytest')); + +echo "Done" +?> +--EXPECTF-- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/trait_exists_basic_001.phpt b/ext/standard/tests/class_object/trait_exists_basic_001.phpt new file mode 100644 index 0000000..19616ab --- /dev/null +++ b/ext/standard/tests/class_object/trait_exists_basic_001.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test trait_exists() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) + * Description: Checks if the trait exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing trait_exists() : basic functionality ***\n"; + +function __autoload($traitName) { + echo "In __autoload($traitName)\n"; +} + +trait MyTrait {} + +echo "Calling trait_exists() on non-existent trait with autoload explicitly enabled:\n"; +var_dump( trait_exists('C', true) ); +echo "\nCalling trait_exists() on existing trait with autoload explicitly enabled:\n"; +var_dump( trait_exists('MyTrait', true) ); + +echo "\nCalling trait_exists() on non-existent trait with autoload explicitly enabled:\n"; +var_dump( trait_exists('D', false) ); +echo "\nCalling trait_exists() on existing trait with autoload explicitly disabled:\n"; +var_dump( trait_exists('MyTrait', false) ); + +echo "\nCalling trait_exists() on non-existent trait with autoload unspecified:\n"; +var_dump( trait_exists('E') ); +echo "\nCalling trait_exists() on existing trait with autoload unspecified:\n"; +var_dump( trait_exists('MyTrait') ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing trait_exists() : basic functionality *** +Calling trait_exists() on non-existent trait with autoload explicitly enabled: +In __autoload(C) +bool(false) + +Calling trait_exists() on existing trait with autoload explicitly enabled: +bool(true) + +Calling trait_exists() on non-existent trait with autoload explicitly enabled: +bool(false) + +Calling trait_exists() on existing trait with autoload explicitly disabled: +bool(true) + +Calling trait_exists() on non-existent trait with autoload unspecified: +In __autoload(E) +bool(false) + +Calling trait_exists() on existing trait with autoload unspecified: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/trait_exists_error_001.phpt b/ext/standard/tests/class_object/trait_exists_error_001.phpt new file mode 100644 index 0000000..b80f06e --- /dev/null +++ b/ext/standard/tests/class_object/trait_exists_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test trait_exists() function : error conditions (wrong number of arguments) +--FILE-- +<?php +/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) + * Description: Checks if the trait exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/** + * Test wrong number of arguments + */ + +echo "*** Testing trait_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing trait_exists() function with Zero arguments --\n"; +var_dump( trait_exists() ); + +//Test trait_exists with one more than the expected number of arguments +echo "\n-- Testing trait_exists() function with more than expected no. of arguments --\n"; +$traitname = 'string_val'; +$autoload = true; +$extra_arg = 10; +var_dump( trait_exists($traitname, $autoload, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing trait_exists() : error conditions *** + +-- Testing trait_exists() function with Zero arguments -- + +Warning: trait_exists() expects at least 1 parameter, 0 given in %s on line 16 +NULL + +-- Testing trait_exists() function with more than expected no. of arguments -- + +Warning: trait_exists() expects at most 2 parameters, 3 given in %s on line 23 +NULL +Done diff --git a/ext/standard/tests/class_object/trait_exists_variation_001.phpt b/ext/standard/tests/class_object/trait_exists_variation_001.phpt new file mode 100644 index 0000000..65ef199 --- /dev/null +++ b/ext/standard/tests/class_object/trait_exists_variation_001.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test trait_exists() function : usage variations - unexpected types for agument 1 +--FILE-- +<?php +/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) + * Description: Checks if the trait exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($traitName) { + echo "In __autoload($traitName)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing trait_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$autoload = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for traitname + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( trait_exists($value, $autoload) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing trait_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +In __autoload(0) +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value 12345 +In __autoload(12345) +bool(false) + +Arg value -2345 +In __autoload(-2345) +bool(false) + +Arg value 10.5 +In __autoload(10.5) +bool(false) + +Arg value -10.5 +In __autoload(-10.5) +bool(false) + +Arg value 101234567000 +In __autoload(101234567000) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(1.07654321E-9) +bool(false) + +Arg value 0.5 +In __autoload(0.5) +bool(false) +Error: 8 - Array to string conversion, %strait_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 1 to be string, array given, %s(77) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_001.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 2 - trait_exists() expects parameter 1 to be string, object given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/trait_exists_variation_002.phpt b/ext/standard/tests/class_object/trait_exists_variation_002.phpt new file mode 100644 index 0000000..a2fcbbf --- /dev/null +++ b/ext/standard/tests/class_object/trait_exists_variation_002.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test trait_exists() function : usage variations - unexpected types for agument 2 +--FILE-- +<?php +/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) + * Description: Checks if the trait exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($traitName) { + echo "In __autoload($traitName)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing trait_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$traitname = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for autoload + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( trait_exists($traitname, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing trait_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(71) +Error: 8 - Undefined variable: unset_var, %s(74) + +Arg value 0 +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value 12345 +In __autoload(string_val) +bool(false) + +Arg value -2345 +In __autoload(string_val) +bool(false) + +Arg value 10.5 +In __autoload(string_val) +bool(false) + +Arg value -10.5 +In __autoload(string_val) +bool(false) + +Arg value 101234567000 +In __autoload(string_val) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(string_val) +bool(false) + +Arg value 0.5 +In __autoload(string_val) +bool(false) +Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL +Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) + +Arg value Array +Error: 2 - trait_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(80) + +Arg value +Error: 2 - trait_exists() expects parameter 2 to be boolean, object given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file |