diff options
author | Robin Fernandes <robinf@php.net> | 2008-03-06 11:02:37 +0000 |
---|---|---|
committer | Robin Fernandes <robinf@php.net> | 2008-03-06 11:02:37 +0000 |
commit | ee0f7bc0ac34ea6b96650bb7715517372d2af711 (patch) | |
tree | 682fdd268766b246e63f0d98174d2db757d6aafb /ext/standard | |
parent | 34c89a26010f97bc6f3321160ba82419388c2af8 (diff) | |
download | php-git-ee0f7bc0ac34ea6b96650bb7715517372d2af711.tar.gz |
Add new tests for class/object functions and features.
Diffstat (limited to 'ext/standard')
42 files changed, 3546 insertions, 0 deletions
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 0000000000..4cb6cbd327 --- /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 0000000000..99c0b89b3c --- /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 0000000000..2141d65eb8 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_001.phpt @@ -0,0 +1,182 @@ +--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) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +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 0000000000..da10cac908 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_002.phpt @@ -0,0 +1,193 @@ +--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) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +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 0000000000..0745601452 --- /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/get_class_error_001.phpt b/ext/standard/tests/class_object/get_class_error_001.phpt new file mode 100644 index 0000000000..b563c31881 --- /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: Wrong parameter count for get_class() in %s on line 14 +NULL +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 0000000000..b2b87af4ec --- /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 0000000000..441bb45d6d --- /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 0000000000..b64f702b85 --- /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 0000000000..6edb108032 --- /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: Wrong parameter count for get_class_methods() in %s on line 16 +NULL + +-- Testing get_class_methods() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_class_methods() 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 0000000000..b881452b4c --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_001.phpt @@ -0,0 +1,172 @@ +--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 + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +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 0000000000..6e40d902a5 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_002.phpt @@ -0,0 +1,34 @@ +--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 +--UEXPECTF-- +*** Testing get_class_methods() : usage variations *** +array(1) { + [0]=> + unicode(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 0000000000..6cbe0b3683 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_001.phpt @@ -0,0 +1,160 @@ +--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 %s on line 58 + +Notice: Undefined variable: unset_var in %s on line 61 + +Arg value: 0 (type: integer) +bool(false) + +Arg value: 1 (type: integer) +bool(false) + +Arg value: 12345 (type: integer) +bool(false) + +Arg value: -2345 (type: integer) +bool(false) + +Arg value: 10.5 (type: double) +bool(false) + +Arg value: -10.5 (type: double) +bool(false) + +Arg value: 101234567000 (type: double) +bool(false) + +Arg value: 1.07654321E-9 (type: double) +bool(false) + +Arg value: 0.5 (type: double) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: 1 (type: boolean) +bool(false) + +Arg value: (type: boolean) +bool(false) + +Arg value: 1 (type: boolean) +bool(false) + +Arg value: (type: boolean) +bool(false) + +Arg value: (type: string) +bool(false) + +Arg value: (type: string) +bool(false) + +Arg value: string (type: string) +bool(false) + +Arg value: string (type: string) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: (type: NULL) +bool(false) +Done
\ No newline at end of file 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 0000000000..911c6e799d --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_002.phpt @@ -0,0 +1,21 @@ +--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 +--UEXPECTF-- +unicode(19) "caseSensitivityTest" +Done
\ No newline at end of file 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 0000000000..123e9772cc --- /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 0000000000..a508443678 --- /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: Wrong parameter count for get_declared_classes() in %s on line 13 +NULL +Done
\ No newline at end of file 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 0000000000..a0ec715187 --- /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 0000000000..93aabb6f61 --- /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: Wrong parameter count for get_declared_interfaces() in %s on line 13 +NULL +Done
\ No newline at end of file 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 0000000000..38ed74fb07 --- /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 0000000000..910926bc1f --- /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 0000000000..67a2705d05 --- /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: Wrong parameter count for get_object_vars() in %s on line 12 +NULL + +-- Testing get_object_vars() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_object_vars() 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 0000000000..89fbc53e93 --- /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 0000000000..73478de79a --- /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 0000000000..70794e7d57 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_003.phpt @@ -0,0 +1,158 @@ +--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 +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
\ 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 0000000000..cf9c3e8674 --- /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: Wrong parameter count for get_parent_class() 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 0000000000..6f2e32805b --- /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 0000000000..f7e5b9df3f --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_variation_002.phpt @@ -0,0 +1,174 @@ +--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) + +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 +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/is_a_error_001.phpt b/ext/standard/tests/class_object/is_a_error_001.phpt new file mode 100644 index 0000000000..d20016a495 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_error_001.phpt @@ -0,0 +1,46 @@ +--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) + * 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'; +$extra_arg = 10; +var_dump( is_a($object, $class_name, $extra_arg) ); + +// 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 -- + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 16 + +Warning: Wrong parameter count for is_a() in %s on line 16 +NULL + +-- Testing is_a() function with less than expected no. of arguments -- + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 21 + +Warning: Wrong parameter count for is_a() in %s on line 21 +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 0000000000..569752dfc6 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_001.phpt @@ -0,0 +1,215 @@ +--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 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 12345 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value -2345 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 10.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value -10.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 101234567000 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1.07654321E-9 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 0.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value string + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value String + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) +Done
\ No newline at end of file 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 0000000000..ed2c475de4 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_002.phpt @@ -0,0 +1,225 @@ +--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 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 12345 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value -2345 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 10.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value -10.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 101234567000 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1.07654321E-9 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 0.5 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value C Instance + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) +Done
\ No newline at end of file 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 0000000000..88e955280c --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_003.phpt @@ -0,0 +1,27 @@ +--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 *** + +Deprecated: is_a(): Deprecated. Please use the instanceof operator in %s on line 13 +bool(true) +Done
\ No newline at end of file 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 0000000000..4403bde4c0 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_error_001.phpt @@ -0,0 +1,40 @@ +--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'; +$extra_arg = 10; +var_dump( is_subclass_of($object, $class_name, $extra_arg) ); + +// 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: Wrong parameter count for is_subclass_of() in %s on line 16 +NULL + +-- Testing is_subclass_of() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for is_subclass_of() in %s on line 21 +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 0000000000..f11183d489 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt @@ -0,0 +1,175 @@ +--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) + +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 +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value string +In __autoload(string) +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value String +In __autoload(String) +Error: 2 - Unknown class passed as parameter, %s(79) +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 0000000000..a45583ce63 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt @@ -0,0 +1,172 @@ +--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) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +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) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) +Error: 8 - Object of class stdClass to string conversion, %s(77) +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_003.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt new file mode 100644 index 0000000000..d4aef12349 --- /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/method_exists_basic_001.phpt b/ext/standard/tests/class_object/method_exists_basic_001.phpt new file mode 100644 index 0000000000..2f11e4c46e --- /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 0000000000..f6b62aa265 --- /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 0000000000..32f62b7e4b --- /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 0000000000..203128c677 --- /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: Wrong parameter count for method_exists() in %s on line 16 +NULL + +-- Testing method_exists() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for method_exists() 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 0000000000..117c211d0d --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_001.phpt @@ -0,0 +1,170 @@ +--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) + +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 +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 0000000000..54d0ef94f5 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_002.phpt @@ -0,0 +1,172 @@ +--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) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +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) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) +Error: 8 - Object of class stdClass to string conversion, %s(77) +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_003.phpt b/ext/standard/tests/class_object/method_exists_variation_003.phpt new file mode 100644 index 0000000000..debe5a35e9 --- /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 |