diff options
Diffstat (limited to 'ext/reflection')
52 files changed, 1866 insertions, 29 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f74b4fe07..28118452b 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.c,v 1.164.2.33.2.39 2007/05/29 08:44:05 helly Exp $ */ +/* $Id: php_reflection.c,v 1.164.2.33.2.45 2007/08/20 17:01:22 sebastian Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -978,6 +978,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde while (func->fname) { if (zend_hash_find(EG(function_table), func->fname, strlen(func->fname) + 1, (void**) &fptr) == FAILURE) { zend_error(E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); + func++; continue; } @@ -2731,7 +2732,7 @@ ZEND_METHOD(reflection_class, getStaticProperties) /* }}} */ /* {{{ proto public mixed ReflectionClass::getStaticPropertyValue(string name [, mixed default]) - Returns the value of a tsstic property */ + Returns the value of a static property */ ZEND_METHOD(reflection_class, getStaticPropertyValue) { reflection_object *intern; @@ -2804,7 +2805,8 @@ ZEND_METHOD(reflection_class, getDefaultProperties) { reflection_object *intern; zend_class_entry *ce; - int count; + int count, i; + HashTable *ht_list[3]; METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0); GET_REFLECTION_OBJECT_PTR(ce); @@ -2812,33 +2814,40 @@ ZEND_METHOD(reflection_class, getDefaultProperties) zend_update_class_constants(ce TSRMLS_CC); - count = zend_hash_num_elements(&ce->default_properties); - if (count > 0) { - HashPosition pos; - zval **prop; + ht_list[0] = CE_STATIC_MEMBERS(ce); + ht_list[1] = &ce->default_properties; + ht_list[2] = NULL; - zend_hash_internal_pointer_reset_ex(&ce->default_properties, &pos); - while (zend_hash_get_current_data_ex(&ce->default_properties, (void **) &prop, &pos) == SUCCESS) { - char *key, *class_name, *prop_name; - uint key_len; - ulong num_index; - zval *prop_copy; + for (i = 0; ht_list[i] != NULL; i++) { - zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len, &num_index, 0, &pos); - zend_hash_move_forward_ex(&ce->default_properties, &pos); - zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name); - if (class_name && class_name[0] != '*' && strcmp(class_name, ce->name)) { - /* filter privates from base classes */ - continue; - } + count = zend_hash_num_elements(ht_list[i]); + if (count > 0) { + HashPosition pos; + zval **prop; + + zend_hash_internal_pointer_reset_ex(ht_list[i], &pos); + while (zend_hash_get_current_data_ex(ht_list[i], (void **) &prop, &pos) == SUCCESS) { + char *key, *class_name, *prop_name; + uint key_len; + ulong num_index; + zval *prop_copy; + + zend_hash_get_current_key_ex(ht_list[i], &key, &key_len, &num_index, 0, &pos); + zend_hash_move_forward_ex(ht_list[i], &pos); + zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name); + if (class_name && class_name[0] != '*' && strcmp(class_name, ce->name)) { + /* filter privates from base classes */ + continue; + } - /* copy: enforce read only access */ - ALLOC_ZVAL(prop_copy); - *prop_copy = **prop; - zval_copy_ctor(prop_copy); - INIT_PZVAL(prop_copy); + /* copy: enforce read only access */ + ALLOC_ZVAL(prop_copy); + *prop_copy = **prop; + zval_copy_ctor(prop_copy); + INIT_PZVAL(prop_copy); - add_assoc_zval(return_value, prop_name, prop_copy); + add_assoc_zval(return_value, prop_name, prop_copy); + } } } } @@ -3616,7 +3625,7 @@ ZEND_METHOD(reflection_class, isSubclassOf) case IS_STRING: if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Interface %s does not exist", Z_STRVAL_P(class_name)); + "Class %s does not exist", Z_STRVAL_P(class_name)); return; } class_ce = *pce; @@ -4206,6 +4215,7 @@ ZEND_METHOD(reflection_extension, getFunctions) while (func->fname) { if (zend_hash_find(EG(function_table), func->fname, strlen(func->fname) + 1, (void**) &fptr) == FAILURE) { zend_error(E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); + func++; continue; } @@ -4384,6 +4394,20 @@ ZEND_METHOD(reflection_extension, getDependencies) } /* }}} */ +/* {{{ proto public void ReflectionExtension::info() U + Prints phpinfo block for the extension */ +ZEND_METHOD(reflection_extension, info) +{ + reflection_object *intern; + zend_module_entry *module; + + METHOD_NOTSTATIC_NUMPARAMS(reflection_extension_ptr, 0); + GET_REFLECTION_OBJECT_PTR(module); + + php_info_print_module(module TSRMLS_CC); +} +/* }}} */ + /* {{{ method tables */ static zend_function_entry reflection_exception_functions[] = { {NULL, NULL, NULL} @@ -4675,7 +4699,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_property___construct, 0) ZEND_END_ARG_INFO() static -ZEND_BEGIN_ARG_INFO(arginfo_reflection_property_getValue, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_getValue, 0, 0, 0) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() @@ -4760,6 +4784,7 @@ static zend_function_entry reflection_extension_functions[] = { ZEND_ME(reflection_extension, getClasses, NULL, 0) ZEND_ME(reflection_extension, getClassNames, NULL, 0) ZEND_ME(reflection_extension, getDependencies, NULL, 0) + ZEND_ME(reflection_extension, info, NULL, 0) {NULL, NULL, NULL} }; /* }}} */ @@ -4878,7 +4903,7 @@ PHP_MINFO_FUNCTION(reflection) /* {{{ */ php_info_print_table_start(); php_info_print_table_header(2, "Reflection", "enabled"); - php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.164.2.33.2.39 2007/05/29 08:44:05 helly Exp $"); + php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.164.2.33.2.45 2007/08/20 17:01:22 sebastian Exp $"); php_info_print_table_end(); } /* }}} */ diff --git a/ext/reflection/tests/026.phpt b/ext/reflection/tests/026.phpt new file mode 100644 index 000000000..e4c6a3f86 --- /dev/null +++ b/ext/reflection/tests/026.phpt @@ -0,0 +1,36 @@ +--TEST-- +reflectionExtension::info() +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +$r = new ReflectionExtension("reflection"); +$r->info(); + +date_default_timezone_set('Europe/Berlin'); +$r = new ReflectionExtension("date"); +$r->info(); + +echo "\nDone!\n"; + +--EXPECTF-- +Reflection + +Reflection => enabled +Version => %s + +date + +date/time support => enabled +"Olson" Timezone Database Version => %s +Timezone Database => %s +Default timezone => %s + +Directive => %s => %s +date.timezone => %s => %s +date.default_latitude => %s => %s +date.default_longitude => %s => %s +date.sunset_zenith => %s => %s +date.sunrise_zenith => %s => %s + +Done! diff --git a/ext/reflection/tests/bug41884.phpt b/ext/reflection/tests/bug41884.phpt new file mode 100644 index 000000000..f8c0a0a2b --- /dev/null +++ b/ext/reflection/tests/bug41884.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #41884 (ReflectionClass::getDefaultProperties() does not handle static attributes) +--FILE-- +<?php + +class Foo +{ + protected static $fooStatic = 'foo'; + protected $foo = 'foo'; +} + +$class = new ReflectionClass('Foo'); + +var_dump($class->getDefaultProperties()); + +echo "Done\n"; +?> +--EXPECTF-- +array(2) { + ["fooStatic"]=> + string(3) "foo" + ["foo"]=> + string(3) "foo" +} +Done diff --git a/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt new file mode 100644 index 000000000..27b4bc24a --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() +--FILE-- +<?php +//New instance of class C - defined below +$rc = new ReflectionClass("C"); + +//Get the file name of the PHP script in which C is defined +var_dump($rc->getFileName()); + +//Get the line number at the start of the definition of class C +var_dump($rc->getStartLine()); + +//Get the line number at the end of the definition of class C +var_dump($rc->getEndLine()); + +//Same tests as above but stdclass is internal - so all results should be false. +$rc = new ReflectionClass("stdClass"); +var_dump($rc->getFileName()); +var_dump($rc->getStartLine()); +var_dump($rc->getEndLine()); + +Class C { + +} +?> +--EXPECTF-- +string(%d) "%sreflectionClass_FileInfo_basic.php" +int(20) +int(22) +bool(false) +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_FileInfo_error.phpt b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt new file mode 100644 index 000000000..a74062a3e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt @@ -0,0 +1,37 @@ +--TEST--
+ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() - bad params
+--FILE--
+<?php
+Class C { }
+
+$rc = new ReflectionClass("C");
+$methods = array("getFileName", "getStartLine", "getEndLine");
+
+foreach ($methods as $method) {
+ var_dump($rc->$method());
+ var_dump($rc->$method(null));
+ var_dump($rc->$method('X', 0));
+}
+?>
+--EXPECTF--
+string(%d) "%s"
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10
+NULL
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_constructor_001.phpt b/ext/reflection/tests/reflectionClass_constructor_001.phpt new file mode 100644 index 000000000..06b68b88f --- /dev/null +++ b/ext/reflection/tests/reflectionClass_constructor_001.phpt @@ -0,0 +1,33 @@ +--TEST--
+ReflectionClass::__constructor()
+--FILE--
+<?php
+$r1 = new ReflectionClass("stdClass");
+
+$myInstance = new stdClass;
+$r2 = new ReflectionClass($myInstance);
+
+class TrickClass {
+ function __toString() {
+ //Return the name of another class
+ return "Exception";
+ }
+}
+$myTrickClass = new TrickClass;
+$r3 = new ReflectionClass($myTrickClass);
+
+var_dump($r1, $r2, $r3);
+?>
+--EXPECTF--
+object(ReflectionClass)#%d (1) {
+ ["name"]=>
+ string(8) "stdClass"
+}
+object(ReflectionClass)#%d (1) {
+ ["name"]=>
+ string(8) "stdClass"
+}
+object(ReflectionClass)#%d (1) {
+ ["name"]=>
+ string(10) "TrickClass"
+}
diff --git a/ext/reflection/tests/reflectionClass_constructor_002.phpt b/ext/reflection/tests/reflectionClass_constructor_002.phpt new file mode 100644 index 000000000..97f1b3570 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_constructor_002.phpt @@ -0,0 +1,67 @@ +--TEST--
+ReflectionClass::__constructor() - bad arguments
+--FILE--
+<?php
+try {
+ var_dump(new ReflectionClass());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass(null));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass(true));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass(1));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass(array(1,2,3)));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass("stdClass", 1));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(new ReflectionClass("X"));
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+--EXPECTF--
+
+Warning: ReflectionClass::__construct() expects exactly 1 parameter, 0 given in %s on line 3
+object(ReflectionClass)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+Class does not exist
+Class 1 does not exist
+Class 1 does not exist
+
+Notice: Array to string conversion in %s on line 27
+Class Array does not exist
+
+Warning: ReflectionClass::__construct() expects exactly 1 parameter, 2 given in %s on line 33
+object(ReflectionClass)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+Class X does not exist
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt new file mode 100644 index 000000000..d0909ec4f --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt @@ -0,0 +1,41 @@ +--TEST--
+ReflectionClass::getConstants()
+--FILE--
+<?php
+class C {
+ const a = 'hello from C';
+}
+class D extends C {
+}
+class E extends D {
+}
+class F extends E {
+ const a = 'hello from F';
+}
+class X {
+}
+
+$classes = array("C", "D", "E", "F", "X");
+foreach($classes as $class) {
+ echo "Reflecting on class $class: \n";
+ $rc = new ReflectionClass($class);
+ var_dump($rc->getConstant('a'));
+ var_dump($rc->getConstant('doesntexist'));
+}
+?>
+--EXPECTF--
+Reflecting on class C:
+string(12) "hello from C"
+bool(false)
+Reflecting on class D:
+string(12) "hello from C"
+bool(false)
+Reflecting on class E:
+string(12) "hello from C"
+bool(false)
+Reflecting on class F:
+string(12) "hello from F"
+bool(false)
+Reflecting on class X:
+bool(false)
+bool(false)
diff --git a/ext/reflection/tests/reflectionClass_getConstant_error.phpt b/ext/reflection/tests/reflectionClass_getConstant_error.phpt new file mode 100644 index 000000000..a1e300519 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_error.phpt @@ -0,0 +1,37 @@ +--TEST--
+ReflectionClass::getConstant() - bad params
+--FILE--
+<?php
+class C {
+ const myConst = 1;
+}
+
+$rc = new ReflectionClass("C");
+echo "Check invalid params:\n";
+var_dump($rc->getConstant());
+var_dump($rc->getConstant("myConst", "myConst"));
+var_dump($rc->getConstant(null));
+var_dump($rc->getConstant(1));
+var_dump($rc->getConstant(1.5));
+var_dump($rc->getConstant(true));
+var_dump($rc->getConstant(array(1,2,3)));
+var_dump($rc->getConstant(new C));
+?>
+--EXPECTF--
+Check invalid params:
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 8
+NULL
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 9
+NULL
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string, array given in %s on line 14
+NULL
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string, object given in %s on line 15
+NULL
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstants_basic.phpt b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt new file mode 100644 index 000000000..9abdcc801 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +ReflectionClass::getConstants() +--FILE-- +<?php +class C { + const a = 'hello from C'; +} +class D extends C { +} +class E extends D { +} +class F extends E { + const a = 'hello from F'; +} +class X { +} + +$classes = array('C', 'D', 'E', 'F', 'X'); +foreach($classes as $class) { + echo "Constants from class $class: \n"; + $rc = new ReflectionClass($class); + var_dump($rc->getConstants()); +} +?> +--EXPECTF-- +Constants from class C: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class D: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class E: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class F: +array(1) { + ["a"]=> + string(12) "hello from F" +} +Constants from class X: +array(0) { +} diff --git a/ext/reflection/tests/reflectionClass_getConstants_error.phpt b/ext/reflection/tests/reflectionClass_getConstants_error.phpt new file mode 100644 index 000000000..73c407d65 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionClass::getConstants() +--FILE-- +<?php +class X { +} + +$rc = new reflectionClass('X'); + +//Test invalid arguments +$rc->getConstants('X'); +$rc->getConstants(true); +$rc->getConstants(null); +$rc->getConstants('A', 'B'); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 9 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 10 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 11 diff --git a/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt new file mode 100644 index 000000000..59c87ad66 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt @@ -0,0 +1,82 @@ +--TEST--
+ReflectionClass::getConstructor()
+--FILE--
+<?php
+class NewCtor {
+ function __construct() {}
+}
+
+class ExtendsNewCtor extends NewCtor {
+}
+
+class OldCtor {
+ function OldCtor() {}
+}
+
+class ExtendsOldCtor extends OldCtor {
+}
+
+
+class X {
+ function Y() {}
+}
+
+class Y extends X {
+}
+
+class OldAndNewCtor {
+ function OldAndNewCtor() {}
+ function __construct() {}
+}
+
+class NewAndOldCtor {
+ function __construct() {}
+ function NewAndOldCtor() {}
+}
+class B {
+ function B() {}
+}
+
+class C extends B {
+ function C() {}
+}
+
+class D1 extends C {
+ function __construct() {}
+}
+
+class D2 extends C {
+}
+
+$classes = array('NewCtor', 'ExtendsNewCtor', 'OldCtor', 'ExtendsOldCtor',
+ 'OldAndNewCtor', 'NewAndOldCtor', 'B', 'C', 'D1', 'D2', 'X', 'Y');
+
+foreach ($classes as $class) {
+ $rc = new ReflectionClass($class);
+ $rm = $rc->getConstructor();
+ if ($rm != null) {
+ echo "Constructor of $class: " . $rm->getName() . "\n";
+ } else {
+ echo "No constructor for $class\n";
+ }
+
+}
+
+?>
+--EXPECTF--
+
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
+
+Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Constructor of NewCtor: __construct
+Constructor of ExtendsNewCtor: __construct
+Constructor of OldCtor: OldCtor
+Constructor of ExtendsOldCtor: OldCtor
+Constructor of OldAndNewCtor: __construct
+Constructor of NewAndOldCtor: __construct
+Constructor of B: B
+Constructor of C: C
+Constructor of D1: __construct
+Constructor of D2: C
+No constructor for X
+No constructor for Y
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstructor_error.phpt b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt new file mode 100644 index 000000000..53d19b5ac --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt @@ -0,0 +1,24 @@ +--TEST--
+ReflectionClass::getConstructor() - bad params
+--FILE--
+<?php
+class C {}
+$rc = new ReflectionClass('C');
+var_dump($rc->getConstructor(null));
+var_dump($rc->getConstructor('X'));
+var_dump($rc->getConstructor(true));
+var_dump($rc->getConstructor(array(1,2,3)));
+?>
+--EXPECTF--
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7
+NULL
diff --git a/ext/reflection/tests/reflectionClass_getName_basic.phpt b/ext/reflection/tests/reflectionClass_getName_basic.phpt new file mode 100644 index 000000000..158413f15 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +ReflectionClass::getName() +--FILE-- +<?php +class TrickClass { + function __toString() { + //Return the name of another class + return "Exception"; + } +} + +$r1 = new ReflectionClass("stdClass"); + +$myInstance = new stdClass; +$r2 = new ReflectionClass($myInstance); + +$r3 = new ReflectionClass("TrickClass"); + +var_dump($r1->getName(), $r2->getName(), $r3->getName()); + +?> +--EXPECTF-- +string(8) "stdClass" +string(8) "stdClass" +string(10) "TrickClass" diff --git a/ext/reflection/tests/reflectionClass_getName_error.phpt b/ext/reflection/tests/reflectionClass_getName_error.phpt new file mode 100644 index 000000000..6f5699c93 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getName() - invalid params +--FILE-- +<?php + +$r1 = new ReflectionClass("stdClass"); + +var_dump($r1->getName('X')); +var_dump($r1->getName('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 6 +NULL + diff --git a/ext/reflection/tests/reflectionClass_getName_error1.phpt b/ext/reflection/tests/reflectionClass_getName_error1.phpt new file mode 100644 index 000000000..5590137f8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error1.phpt @@ -0,0 +1,8 @@ +--TEST-- +ReflectionClass::getName - forbid static invocation +--FILE-- +<?php +ReflectionClass::getName(); +?> +--EXPECTF-- +Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 diff --git a/ext/reflection/tests/reflectionClass_isInstance_basic.phpt b/ext/reflection/tests/reflectionClass_isInstance_basic.phpt new file mode 100644 index 000000000..e8b1e9d80 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +ReflectionClass::isInstance() +--FILE-- +<?php +class A {} +class B extends A {} + +interface I {} +class C implements I {} + +class X {} + +$classes = array("A", "B", "C", "I", "X"); + +$instances = array( "myA" => new A, + "myB" => new B, + "myC" => new C, + "myX" => new X ); + +foreach ($classes as $class) { + $rc = new ReflectionClass($class); + + foreach ($instances as $name => $instance) { + echo "is $name a $class? "; + var_dump($rc->isInstance($instance)); + } + +} + +?> +--EXPECTF-- +is myA a A? bool(true) +is myB a A? bool(false) +is myC a A? bool(false) +is myX a A? bool(false) +is myA a B? bool(false) +is myB a B? bool(true) +is myC a B? bool(false) +is myX a B? bool(false) +is myA a C? bool(false) +is myB a C? bool(false) +is myC a C? bool(true) +is myX a C? bool(false) +is myA a I? bool(false) +is myB a I? bool(false) +is myC a I? bool(false) +is myX a I? bool(false) +is myA a X? bool(false) +is myB a X? bool(false) +is myC a X? bool(false) +is myX a X? bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInstance_error.phpt b/ext/reflection/tests/reflectionClass_isInstance_error.phpt new file mode 100644 index 000000000..2c4f49b7d --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClass::isInstance() - invalid params +--FILE-- +<?php +class X {} + +$rc = new ReflectionClass("X"); +$instance = new X; + +var_dump($rc->isInstance()); +var_dump($rc->isInstance($instance, $instance)); +var_dump($rc->isInstance(1)); +var_dump($rc->isInstance(1.5)); +var_dump($rc->isInstance(true)); +var_dump($rc->isInstance('X')); +var_dump($rc->isInstance(null)); + +?> +--EXPECTF-- +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 2 given in %s on line 8 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, %s given in %s on line 9 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 10 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 11 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, string given in %s on line 12 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, null given in %s on line 13 +NULL diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt new file mode 100644 index 000000000..6ebcfa99a --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +<?php +class C { +} + +interface iface { + function f1(); +} + +class ifaceImpl implements iface { + function f1() {} +} + +abstract class abstractClass { + function f1() {} + abstract function f2(); +} + +class D extends abstractClass { + function f2() {} +} + +$classes = array("C", "iface", "ifaceImpl", "abstractClass", "D"); + +foreach($classes as $class ) { + $reflectionClass = new ReflectionClass($class); + echo "Is $class instantiable? "; + var_dump($reflectionClass->IsInstantiable()); + +} + +?> +--EXPECTF-- +Is C instantiable? bool(true) +Is iface instantiable? bool(false) +Is ifaceImpl instantiable? bool(true) +Is abstractClass instantiable? bool(false) +Is D instantiable? bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt new file mode 100644 index 000000000..cc31a2f42 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +<?php +class privateCtorOld { + private function privateCtorOld() {} +} +$reflectionClass = new ReflectionClass("privateCtorOld"); + +var_dump($reflectionClass->IsInstantiable('X')); +var_dump($reflectionClass->IsInstantiable(0, null)); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 8 +NULL diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt new file mode 100644 index 000000000..1cf3e613e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt @@ -0,0 +1,50 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +<?php +class noCtor { +} + +class publicCtorNew { + public function __construct() {} +} + +class protectedCtorNew { + protected function __construct() {} +} + +class privateCtorNew { + private function __construct() {} +} + +class publicCtorOld { + public function publicCtorOld() {} +} + +class protectedCtorOld { + protected function protectedCtorOld() {} +} + +class privateCtorOld { + private function privateCtorOld() {} +} + + +$classes = array("noCtor", "publicCtorNew", "protectedCtorNew", "privateCtorNew", + "publicCtorOld", "protectedCtorOld", "privateCtorOld"); + +foreach($classes as $class ) { + $reflectionClass = new ReflectionClass($class); + echo "Is $class instantiable? "; + var_dump($reflectionClass->IsInstantiable()); +} + +?> +--EXPECTF-- +Is noCtor instantiable? bool(true) +Is publicCtorNew instantiable? bool(true) +Is protectedCtorNew instantiable? bool(false) +Is privateCtorNew instantiable? bool(false) +Is publicCtorOld instantiable? bool(true) +Is protectedCtorOld instantiable? bool(false) +Is privateCtorOld instantiable? bool(false) diff --git a/ext/reflection/tests/reflectionClass_isInternal_basic.phpt b/ext/reflection/tests/reflectionClass_isInternal_basic.phpt new file mode 100644 index 000000000..2eaacb67f --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionClass::isInternal() +--FILE-- +<?php +class C { +} + +$r1 = new ReflectionClass("stdClass"); +$r2 = new ReflectionClass("ReflectionClass"); +$r3 = new ReflectionClass("ReflectionProperty"); +$r4 = new ReflectionClass("Exception"); +$r5 = new ReflectionClass("C"); + +var_dump($r1->isInternal(), $r2->isInternal(), $r3->isInternal(), + $r4->isInternal(), $r5->isInternal()); +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_isInternal_error.phpt b/ext/reflection/tests/reflectionClass_isInternal_error.phpt new file mode 100644 index 000000000..b1117e830 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::isInternal() - invalid params +--FILE-- +<?php +$r1 = new ReflectionClass("stdClass"); +var_dump($r1->isInternal('X')); +var_dump($r1->isInternal('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 3 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 4 +NULL diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt new file mode 100644 index 000000000..94fcf00ec --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt @@ -0,0 +1,103 @@ +--TEST-- +ReflectionClass::isSubclassOf() +--FILE-- +<?php +class A {} +class B extends A {} +class C extends B {} + +interface I {} +class X implements I {} + +$classNames = array('A', 'B', 'C', 'I', 'X'); + +foreach ($classNames as $className) { + $rcs[$className] = new ReflectionClass($className); +} + +foreach ($rcs as $childName => $child) { + foreach ($rcs as $parentName => $parent) { + echo "Is " . $childName . " a subclass of " . $parentName . "? \n"; + echo " - Using object argument: "; + var_dump($child->isSubclassOf($parent)); + echo " - Using string argument: "; + var_dump($child->isSubclassOf($parentName)); + } +} +?> +--EXPECTF-- +Is A a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of A? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is B a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of A? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of B? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of I? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is X a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt new file mode 100644 index 000000000..7d929fafd --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::isSubclassOf() - invalid number of parameters +--FILE-- +<?php +class A {} +$rc = new ReflectionClass('A'); + +var_dump($rc->isSubclassOf()); +var_dump($rc->isSubclassOf('A',5)); + +?> +--EXPECTF-- +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 5 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6 +NULL diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt new file mode 100644 index 000000000..2fabd023e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt @@ -0,0 +1,16 @@ +--TEST-- +ReflectionClass::isSubclassOf() - non-existent class error +--FILE-- +<?php +class A {} +$rc = new ReflectionClass('A'); + +var_dump($rc->isSubclassOf('X')); + +?> +--EXPECTF-- +Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:5 +Stack trace: +#0 %s(5): ReflectionClass->isSubclassOf('X') +#1 {main} + thrown in %s on line 5 diff --git a/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt b/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt new file mode 100644 index 000000000..af43fcefa --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionClass::isUserDefined() +--FILE-- +<?php +class C { +} + +$r1 = new ReflectionClass("stdClass"); +$r2 = new ReflectionClass("ReflectionClass"); +$r3 = new ReflectionClass("ReflectionProperty"); +$r4 = new ReflectionClass("Exception"); +$r5 = new ReflectionClass("C"); + +var_dump($r1->isUserDefined(), $r2->isUserDefined(), $r3->isUserDefined(), + $r4->isUserDefined(), $r5->isUserDefined()); +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt b/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt new file mode 100644 index 000000000..077e4d6a6 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::isUserDefined() - invalid params. +--FILE-- +<?php +$r1 = new ReflectionClass("stdClass"); +var_dump($r1->isUserDefined('X')); +var_dump($r1->isUserDefined('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 3 +NULL + +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 4 +NULL diff --git a/ext/reflection/tests/reflectionObject_FileInfo_basic.phpt b/ext/reflection/tests/reflectionObject_FileInfo_basic.phpt new file mode 100644 index 000000000..a1334f4d6 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_FileInfo_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +ReflectionObject::getFileName(), ReflectionObject::getStartLine(), ReflectionObject::getEndLine() - basic function +--FILE-- +<?php +$rc = new ReflectionObject(new C); +var_dump($rc->getFileName()); +var_dump($rc->getStartLine()); +var_dump($rc->getEndLine()); + +$rc = new ReflectionObject(new stdclass); +var_dump($rc->getFileName()); +var_dump($rc->getStartLine()); +var_dump($rc->getEndLine()); + +Class C { + +} +?> +--EXPECTF-- +string(%d) "%sreflectionObject_FileInfo_basic.php" +int(12) +int(14) +bool(false) +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionObject_FileInfo_error.phpt b/ext/reflection/tests/reflectionObject_FileInfo_error.phpt new file mode 100644 index 000000000..f66d2fb59 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_FileInfo_error.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionObject::getFileName(), ReflectionObject::getStartLine(), ReflectionObject::getEndLine() -invalid aparams +--FILE-- +<?php +Class C { } + +$rc = new ReflectionObject(new C); +$methods = array("getFileName", "getStartLine", "getEndLine"); + +foreach ($methods as $method) { + var_dump($rc->$method()); + var_dump($rc->$method(null)); + var_dump($rc->$method('X', 0)); +} +?> +--EXPECTF-- +string(%d) "%s" + +Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10 +NULL +int(2) + +Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10 +NULL +int(2) + +Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10 +NULL diff --git a/ext/reflection/tests/reflectionObject_constructor_basic.phpt b/ext/reflection/tests/reflectionObject_constructor_basic.phpt new file mode 100644 index 000000000..8f4a9082c --- /dev/null +++ b/ext/reflection/tests/reflectionObject_constructor_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionObject::__construct - basic function test +--FILE-- +<?php +$r1 = new ReflectionObject(new stdClass); +var_dump($r1); + +class C { } +$myInstance = new C; +$r2 = new ReflectionObject($myInstance); +var_dump($r2); + +$r3 = new ReflectionObject($r2); +var_dump($r3); +?> +--EXPECTF-- +object(ReflectionObject)#%d (1) { + ["name"]=> + string(8) "stdClass" +} +object(ReflectionObject)#%d (1) { + ["name"]=> + string(1) "C" +} +object(ReflectionObject)#%d (1) { + ["name"]=> + string(16) "ReflectionObject" +} diff --git a/ext/reflection/tests/reflectionObject_constructor_error.phpt b/ext/reflection/tests/reflectionObject_constructor_error.phpt new file mode 100644 index 000000000..baa6129ed --- /dev/null +++ b/ext/reflection/tests/reflectionObject_constructor_error.phpt @@ -0,0 +1,49 @@ +--TEST-- +ReflectionObject::__construct - invalid arguments +--FILE-- +<?php + +var_dump(new ReflectionObject()); +var_dump(new ReflectionObject('stdClass')); +$myInstance = new stdClass; +var_dump(new ReflectionObject($myInstance, $myInstance)); +var_dump(new ReflectionObject(0)); +var_dump(new ReflectionObject(null)); +var_dump(new ReflectionObject(array(1,2))); +?> +--EXPECTF-- +Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 3 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} + +Warning: ReflectionObject::__construct() expects parameter 1 to be object, string given in %s on line 4 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} + +Warning: ReflectionObject::__construct() expects exactly 1 parameter, 2 given in %s on line 6 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} + +Warning: ReflectionObject::__construct() expects parameter 1 to be object, integer given in %s on line 7 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} + +Warning: ReflectionObject::__construct() expects parameter 1 to be object, null given in %s on line 8 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} + +Warning: ReflectionObject::__construct() expects parameter 1 to be object, array given in %s on line 9 +object(ReflectionObject)#%d (1) { + ["name"]=> + string(0) "" +} diff --git a/ext/reflection/tests/reflectionObject_getConstant_basic.phpt b/ext/reflection/tests/reflectionObject_getConstant_basic.phpt new file mode 100644 index 000000000..3d151bc7d --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstant_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionObject::getConstant() basic function test +--FILE-- +<?php +class C { + const a = 'hello from C'; +} +class D extends C { +} +class E extends D { +} +class F extends E { + const a = 'hello from F'; +} +class X { +} + +$classes = array("C", "D", "E", "F", "X"); +foreach($classes as $class) { + echo "Reflecting on instance of class $class: \n"; + $rc = new ReflectionObject(new $class); + var_dump($rc->getConstant('a')); + var_dump($rc->getConstant('doesntexist')); +} +?> +--EXPECTF-- +Reflecting on instance of class C: +string(12) "hello from C" +bool(false) +Reflecting on instance of class D: +string(12) "hello from C" +bool(false) +Reflecting on instance of class E: +string(12) "hello from C" +bool(false) +Reflecting on instance of class F: +string(12) "hello from F" +bool(false) +Reflecting on instance of class X: +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionObject_getConstant_error.phpt b/ext/reflection/tests/reflectionObject_getConstant_error.phpt new file mode 100644 index 000000000..3f12f3a1e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstant_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +ReflectionObject::getConstant() - invalid params +--FILE-- +<?php +class C { + const myConst = 1; +} + +$rc = new ReflectionObject(new C); +var_dump($rc->getConstant()); +var_dump($rc->getConstant("myConst", "myConst")); +var_dump($rc->getConstant(null)); +var_dump($rc->getConstant(1)); +var_dump($rc->getConstant(1.5)); +var_dump($rc->getConstant(true)); +var_dump($rc->getConstant(array(1,2,3))); +var_dump($rc->getConstant(new C)); +?> +--EXPECTF-- +Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 8 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string, array given in %s on line 13 +NULL + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string, object given in %s on line 14 +NULL diff --git a/ext/reflection/tests/reflectionObject_getConstants_basic.phpt b/ext/reflection/tests/reflectionObject_getConstants_basic.phpt new file mode 100644 index 000000000..6479ec90e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstants_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +ReflectionObject::getConstants() - basic function test +--FILE-- +<?php +class C { + const a = 'hello from C'; +} +class D extends C { +} +class E extends D { +} +class F extends E { + const a = 'hello from F'; +} +class X { +} + +$classes = array("C", "D", "E", "F", "X"); +foreach($classes as $class) { + echo "Reflecting on instance of class $class: \n"; + $rc = new ReflectionObject(new $class); + var_dump($rc->getConstants()); +} + +?> +--EXPECTF-- +Reflecting on instance of class C: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Reflecting on instance of class D: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Reflecting on instance of class E: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Reflecting on instance of class F: +array(1) { + ["a"]=> + string(12) "hello from F" +} +Reflecting on instance of class X: +array(0) { +} diff --git a/ext/reflection/tests/reflectionObject_getConstants_error.phpt b/ext/reflection/tests/reflectionObject_getConstants_error.phpt new file mode 100644 index 000000000..81ec9ed2e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstants_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +ReflectionObject::getConstants() - invalid params +--FILE-- +<?php +class X { +} + +$rc = new ReflectionObject(new X); + +$rc->getConstants('X'); +$rc->getConstants(true); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 7 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8 + diff --git a/ext/reflection/tests/reflectionObject_getConstructor_basic.phpt b/ext/reflection/tests/reflectionObject_getConstructor_basic.phpt new file mode 100644 index 000000000..a784f6d9e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstructor_basic.phpt @@ -0,0 +1,82 @@ +--TEST-- +ReflectionObject::getConstructor() - basic function test +--FILE-- +<?php +class NewCtor { + function __construct() {} +} + +class ExtendsNewCtor extends NewCtor { +} + +class OldCtor { + function OldCtor() {} +} + +class ExtendsOldCtor extends OldCtor { +} + + +class X { + function Y() {} +} + +class Y extends X { +} + +class OldAndNewCtor { + function OldAndNewCtor() {} + function __construct() {} +} + +class NewAndOldCtor { + function __construct() {} + function NewAndOldCtor() {} +} +class B { + function B() {} +} + +class C extends B { + function C() {} +} + +class D1 extends C { + function __construct() {} +} + +class D2 extends C { +} + +$classes = array('NewCtor', 'ExtendsNewCtor', 'OldCtor', 'ExtendsOldCtor', + 'OldAndNewCtor', 'NewAndOldCtor', 'B', 'C', 'D1', 'D2', 'X', 'Y'); + +foreach ($classes as $class) { + $rc = new ReflectionObject(new $class); + $rm = $rc->getConstructor(); + if ($rm != null) { + echo "Constructor of $class: " . $rm->getName() . "\n"; + } else { + echo "No constructor for $class\n"; + } + +} + +?> +--EXPECTF-- + +Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26 + +Strict Standards: %s for class NewAndOldCtor in %s on line 31 +Constructor of NewCtor: __construct +Constructor of ExtendsNewCtor: __construct +Constructor of OldCtor: OldCtor +Constructor of ExtendsOldCtor: OldCtor +Constructor of OldAndNewCtor: __construct +Constructor of NewAndOldCtor: __construct +Constructor of B: B +Constructor of C: C +Constructor of D1: __construct +Constructor of D2: C +No constructor for X +No constructor for Y diff --git a/ext/reflection/tests/reflectionObject_getConstructor_error.phpt b/ext/reflection/tests/reflectionObject_getConstructor_error.phpt new file mode 100644 index 000000000..5cabc2ed1 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getConstructor_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionObject::getConstructor() - invalid params +--FILE-- +<?php +class C {} +$rc = new ReflectionObject(new C); +var_dump($rc->getConstructor(null)); +var_dump($rc->getConstructor('X')); +var_dump($rc->getConstructor(true)); +var_dump($rc->getConstructor(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7 +NULL diff --git a/ext/reflection/tests/reflectionObject_getName_basic.phpt b/ext/reflection/tests/reflectionObject_getName_basic.phpt new file mode 100644 index 000000000..db0cbfb08 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getName_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionObject::getName() - basic function test +--FILE-- +<?php +$r0 = new ReflectionObject(); +var_dump($r0->getName()); + +$r1 = new ReflectionObject(new stdClass); +var_dump($r1->getName()); + +class C { } +$myInstance = new C; +$r2 = new ReflectionObject($myInstance); +var_dump($r2->getName()); + +$r3 = new ReflectionObject($r2); +var_dump($r3->getName()); + +?> +--EXPECTF-- + +Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 2 +string(0) "" +string(8) "stdClass" +string(1) "C" +string(16) "ReflectionObject" + diff --git a/ext/reflection/tests/reflectionObject_getName_error.phpt b/ext/reflection/tests/reflectionObject_getName_error.phpt new file mode 100644 index 000000000..eb64244c1 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getName_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionObject::getname() - invalid params +--FILE-- +<?php +class C { } +$myInstance = new C; +$r2 = new ReflectionObject($myInstance); + +$r3 = new ReflectionObject($r2); + +var_dump($r3->getName(null)); +var_dump($r3->getName('x','y')); +var_dump($r3->getName(0)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 8 +NULL + +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 10 +NULL diff --git a/ext/reflection/tests/reflectionObject_getName_error1.phpt b/ext/reflection/tests/reflectionObject_getName_error1.phpt new file mode 100644 index 000000000..26c342d7f --- /dev/null +++ b/ext/reflection/tests/reflectionObject_getName_error1.phpt @@ -0,0 +1,8 @@ +--TEST-- +ReflectionObject::getName - forbid static invocation +--FILE-- +<?php +ReflectionObject::getName(); +?> +--EXPECTF-- +Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 diff --git a/ext/reflection/tests/reflectionObject_isInstance_basic.phpt b/ext/reflection/tests/reflectionObject_isInstance_basic.phpt new file mode 100644 index 000000000..51d42fdf9 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInstance_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +ReflectionObject::isInstance() - basic function test +--FILE-- +<?php +class A {} +class B extends A {} +class X {} + +$classes = array("A", "B", "X"); + +$instances = array( "myA" => new A, + "myB" => new B, + "myX" => new X ); + +foreach ($classes as $class) { + $ro = new ReflectionObject(new $class); + foreach ($instances as $name => $instance) { + echo "is $name a $class? "; + var_dump($ro->isInstance($instance)); + } +} + +?> +--EXPECTF-- +is myA a A? bool(true) +is myB a A? bool(false) +is myX a A? bool(false) +is myA a B? bool(false) +is myB a B? bool(true) +is myX a B? bool(false) +is myA a X? bool(false) +is myB a X? bool(false) +is myX a X? bool(true) diff --git a/ext/reflection/tests/reflectionObject_isInstance_error.phpt b/ext/reflection/tests/reflectionObject_isInstance_error.phpt new file mode 100644 index 000000000..692c2f849 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInstance_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionObject::isInstance() - invalid params +--FILE-- +<?php +class X {} +$instance = new X; +$ro = new ReflectionObject(new X); + +var_dump($ro->isInstance()); +var_dump($ro->isInstance($instance, $instance)); +var_dump($ro->isInstance(1)); +var_dump($ro->isInstance(1.5)); +var_dump($ro->isInstance(true)); +var_dump($ro->isInstance('X')); +var_dump($ro->isInstance(null)); + +?> +--EXPECTF-- +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 0 given in %s on line 6 +NULL + +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 2 given in %s on line 7 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, integer given in %s on line 8 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 9 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 10 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, string given in %s on line 11 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, null given in %s on line 12 +NULL diff --git a/ext/reflection/tests/reflectionObject_isInstantiable_basic.phpt b/ext/reflection/tests/reflectionObject_isInstantiable_basic.phpt new file mode 100644 index 000000000..4b8a6ec22 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInstantiable_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionObject::IsInstantiable() - basic function test +--FILE-- +<?php +class C { +} + +interface iface { + function f1(); +} + +class ifaceImpl implements iface { + function f1() {} +} + +abstract class abstractClass { + function f1() {} + abstract function f2(); +} + +class D extends abstractClass { + function f2() {} +} + +$classes = array("C", "ifaceImpl", "D"); + +foreach($classes as $class ) { + $ro = new ReflectionObject(new $class); + echo "Is $class instantiable? "; + var_dump($ro->IsInstantiable()); +} +?> +--EXPECTF-- +Is C instantiable? bool(true) +Is ifaceImpl instantiable? bool(true) +Is D instantiable? bool(true) diff --git a/ext/reflection/tests/reflectionObject_isInstantiable_error.phpt b/ext/reflection/tests/reflectionObject_isInstantiable_error.phpt new file mode 100644 index 000000000..8f418ac0e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInstantiable_error.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionObject::IsInstantiable() - invalid params +--FILE-- +<?php +class privateCtorOld { + private function privateCtorOld() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} +$reflectionObject = privateCtorOld::reflectionObjectFactory(); + +var_dump($reflectionObject->IsInstantiable('X')); +var_dump($reflectionObject->IsInstantiable(0, null)); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 10 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 11 +NULL diff --git a/ext/reflection/tests/reflectionObject_isInstantiable_variation.phpt b/ext/reflection/tests/reflectionObject_isInstantiable_variation.phpt new file mode 100644 index 000000000..ac7199c09 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInstantiable_variation.phpt @@ -0,0 +1,78 @@ +--TEST-- +ReflectionObject::IsInstantiable() - variation - constructors +--FILE-- +<?php + +class noCtor { + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class publicCtorNew { + public function __construct() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class protectedCtorNew { + protected function __construct() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class privateCtorNew { + private function __construct() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class publicCtorOld { + public function publicCtorOld() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class protectedCtorOld { + protected function protectedCtorOld() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + +class privateCtorOld { + private function privateCtorOld() {} + public static function reflectionObjectFactory() { + return new ReflectionObject(new self); + } +} + + +$reflectionObjects = array( + noCtor::reflectionObjectFactory(), + publicCtorNew::reflectionObjectFactory(), + protectedCtorNew::reflectionObjectFactory(), + privateCtorNew::reflectionObjectFactory(), + publicCtorOld::reflectionObjectFactory(), + protectedCtorOld::reflectionObjectFactory(), + privateCtorOld::reflectionObjectFactory() + ); + +foreach($reflectionObjects as $reflectionObject ) { + $name = $reflectionObject->getName(); + echo "Is $name instantiable? "; + var_dump($reflectionObject->IsInstantiable()); +} +?> +--EXPECTF-- +Is noCtor instantiable? bool(true) +Is publicCtorNew instantiable? bool(true) +Is protectedCtorNew instantiable? bool(false) +Is privateCtorNew instantiable? bool(false) +Is publicCtorOld instantiable? bool(true) +Is protectedCtorOld instantiable? bool(false) +Is privateCtorOld instantiable? bool(false) diff --git a/ext/reflection/tests/reflectionObject_isInternal_basic.phpt b/ext/reflection/tests/reflectionObject_isInternal_basic.phpt new file mode 100644 index 000000000..066bca70e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInternal_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionObject::isInternal() - basic function test +--FILE-- +<?php +class C { +} + +$r1 = new ReflectionObject(new stdClass); +$r2 = new ReflectionObject(new ReflectionClass('C')); +$r3 = new ReflectionObject(new ReflectionProperty('Exception', 'message')); +$r4 = new ReflectionObject(new Exception); +$r5 = new ReflectionObject(new C); + +var_dump($r1->isInternal(), $r2->isInternal(), $r3->isInternal(), + $r4->isInternal(), $r5->isInternal()); + +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionObject_isInternal_error.phpt b/ext/reflection/tests/reflectionObject_isInternal_error.phpt new file mode 100644 index 000000000..c22d74807 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isInternal_error.phpt @@ -0,0 +1,15 @@ +--TEST-- +ReflectionObject::isInternal() - invalid params +--FILE-- +<?php + +$r1 = new ReflectionObject(new stdClass); +var_dump($r1->isInternal('X')); +var_dump($r1->isInternal('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 5 +NULL diff --git a/ext/reflection/tests/reflectionObject_isSubclassOf_basic.phpt b/ext/reflection/tests/reflectionObject_isSubclassOf_basic.phpt new file mode 100644 index 000000000..e89066a7e --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isSubclassOf_basic.phpt @@ -0,0 +1,116 @@ +--TEST-- +ReflectionObject::isSubclassOf() - basic function test +--FILE-- +<?php +class A {} +class B extends A {} +class C extends B {} + +interface I {} +class X implements I {} + +$classNames = array('A', 'B', 'C', 'I', 'X'); + +//Create ReflectionClasses +foreach ($classNames as $className) { + $rcs[$className] = new ReflectionClass($className); +} + +//Create ReflectionObjects +foreach ($classNames as $className) { + if ($rcs[$className]->isInstantiable()) { + $ros[$className] = new ReflectionObject(new $className); + } +} + +foreach ($ros as $childName => $child) { + foreach ($rcs as $parentName => $parent) { + echo "Is " . $childName . " a subclass of " . $parentName . "? \n"; + echo " - Using ReflectionClass object argument: "; + var_dump($child->isSubclassOf($parent)); + if ($parent->isInstantiable()) { + echo " - Using ReflectionObject object argument: "; + var_dump($child->isSubclassOf($ros[$parentName])); + } + echo " - Using string argument: "; + var_dump($child->isSubclassOf($parentName)); + } +} +?> +--EXPECTF-- +Is A a subclass of A? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of B? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of C? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of I? + - Using ReflectionClass object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of X? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of A? + - Using ReflectionClass object argument: bool(true) + - Using ReflectionObject object argument: bool(true) + - Using string argument: bool(true) +Is B a subclass of B? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of C? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of I? + - Using ReflectionClass object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of X? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of A? + - Using ReflectionClass object argument: bool(true) + - Using ReflectionObject object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of B? + - Using ReflectionClass object argument: bool(true) + - Using ReflectionObject object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of C? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of I? + - Using ReflectionClass object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of X? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of A? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of B? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of C? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of I? + - Using ReflectionClass object argument: bool(true) + - Using string argument: bool(true) +Is X a subclass of X? + - Using ReflectionClass object argument: bool(false) + - Using ReflectionObject object argument: bool(false) + - Using string argument: bool(false) diff --git a/ext/reflection/tests/reflectionObject_isSubclassOf_error.phpt b/ext/reflection/tests/reflectionObject_isSubclassOf_error.phpt new file mode 100644 index 000000000..9387b7dcb --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isSubclassOf_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionObject::isSubclassOf() - invalid params +--FILE-- +<?php +class A {} +$ro = new ReflectionObject(new A); + +var_dump($ro->isSubclassOf()); +var_dump($ro->isSubclassOf('A',5)); +var_dump($ro->isSubclassOf('X')); + +?> +--EXPECTF-- +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 5 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6 +NULL + +Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:7 +Stack trace: +#0 %s(7): ReflectionClass->isSubclassOf('X') +#1 {main} + thrown in %s on line 7 diff --git a/ext/reflection/tests/reflectionObject_isUserDefined_basic.phpt b/ext/reflection/tests/reflectionObject_isUserDefined_basic.phpt new file mode 100644 index 000000000..4cb08fcb6 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isUserDefined_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionObject::isUserDefined() - basic function test +--FILE-- +<?php +class C { +} + +$r1 = new ReflectionObject(new stdClass); +$r2 = new ReflectionObject(new ReflectionClass('C')); +$r3 = new ReflectionObject(new ReflectionProperty('Exception', 'message')); +$r4 = new ReflectionObject(new Exception); +$r5 = new ReflectionObject(new C); + +var_dump($r1->isUserDefined(), $r2->isUserDefined(), $r3->isUserDefined(), + $r4->isUserDefined(), $r5->isUserDefined()); + +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionObject_isUserDefined_error.phpt b/ext/reflection/tests/reflectionObject_isUserDefined_error.phpt new file mode 100644 index 000000000..70533cf3d --- /dev/null +++ b/ext/reflection/tests/reflectionObject_isUserDefined_error.phpt @@ -0,0 +1,15 @@ +--TEST-- +ReflectionObject::isUserDefined() - invalid params +--FILE-- +<?php +$r1 = new ReflectionObject(new stdClass); + +var_dump($r1->isUserDefined('X')); +var_dump($r1->isUserDefined('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 5 +NULL |
