diff options
Diffstat (limited to 'ext/reflection')
109 files changed, 6944 insertions, 873 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 88791a3fe..0f53f6d09 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.c,v 1.164.2.33.2.50 2008/03/13 15:56:21 iliaa Exp $ */ +/* $Id: php_reflection.c,v 1.164.2.33.2.55 2008/12/31 11:17:42 sebastian Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -634,7 +634,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg *zv = precv->op2.u.constant; zval_copy_ctor(zv); INIT_PZVAL(zv); - zval_update_constant(&zv, (void*)1 TSRMLS_CC); + zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC); if (Z_TYPE_P(zv) == IS_BOOL) { if (Z_LVAL_P(zv)) { string_write(str, "true", sizeof("true")-1); @@ -1341,6 +1341,9 @@ ZEND_METHOD(reflection, getModifierNames) if (modifiers & (ZEND_ACC_FINAL | ZEND_ACC_FINAL_CLASS)) { add_next_index_stringl(return_value, "final", sizeof("final")-1, 1); } + if (modifiers & ZEND_ACC_IMPLICIT_PUBLIC) { + add_next_index_stringl(return_value, "public", sizeof("public")-1, 1); + } /* These are mutually exclusive */ switch (modifiers & ZEND_ACC_PPP_MASK) { @@ -1871,7 +1874,7 @@ ZEND_METHOD(reflection_parameter, __construct) if (zend_hash_find(&ce->function_table, lcname, lcname_len + 1, (void **) &fptr) == FAILURE) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s() does not exist", Z_STRVAL_PP(classref), Z_TYPE_PP(method), Z_STRVAL_PP(method)); + "Method %s::%s() does not exist", ce->name, Z_STRVAL_PP(method)); return; } efree(lcname); @@ -3136,9 +3139,25 @@ ZEND_METHOD(reflection_class, getProperty) } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) { - reflection_property_factory(ce, property_info, return_value TSRMLS_CC); - return; + if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) { + if ((property_info->flags & ZEND_ACC_SHADOW) == 0) { + reflection_property_factory(ce, property_info, return_value TSRMLS_CC); + return; + } + } else if (intern->obj) { + /* Check for dynamic properties */ + if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) { + zend_property_info property_info_tmp; + property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC; + property_info_tmp.name = name; + property_info_tmp.name_length = name_len; + property_info_tmp.h = zend_get_hash_value(name, name_len+1); + property_info_tmp.doc_comment = NULL; + property_info_tmp.ce = ce; + + reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC); + return; + } } if ((tmp = strstr(name, "::")) != NULL) { classname_len = tmp - name; @@ -3784,12 +3803,12 @@ ZEND_METHOD(reflection_property, __construct) { zval *propname, *classname; char *name_str, *class_name, *prop_name; - int name_len; + int name_len, dynam_prop = 0; zval *object; reflection_object *intern; zend_class_entry **pce; zend_class_entry *ce; - zend_property_info *property_info; + zend_property_info *property_info = NULL; property_reference *reference; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) { @@ -3823,12 +3842,19 @@ ZEND_METHOD(reflection_property, __construct) } if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Property %s::$%s does not exist", ce->name, name_str); - return; + /* Check for dynamic properties */ + if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) { + if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname TSRMLS_CC), name_str, name_len+1)) { + dynam_prop = 1; + } + } + if (dynam_prop == 0) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str); + return; + } } - if (!(property_info->flags & ZEND_ACC_PRIVATE)) { + if (dynam_prop == 0 && (property_info->flags & ZEND_ACC_PRIVATE) == 0) { /* we have to search the class hierarchy for this (implicit) public or protected property */ zend_class_entry *tmp_ce = ce; zend_property_info *tmp_info; @@ -3844,14 +3870,27 @@ ZEND_METHOD(reflection_property, __construct) ZVAL_STRINGL(classname, ce->name, ce->name_length, 1); zend_hash_update(Z_OBJPROP_P(object), "class", sizeof("class"), (void **) &classname, sizeof(zval *), NULL); - zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name); MAKE_STD_ZVAL(propname); - ZVAL_STRING(propname, prop_name, 1); + if (dynam_prop == 0) { + zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name); + ZVAL_STRING(propname, prop_name, 1); + } else { + ZVAL_STRINGL(propname, name_str, name_len, 1); + } zend_hash_update(Z_OBJPROP_P(object), "name", sizeof("name"), (void **) &propname, sizeof(zval *), NULL); reference = (property_reference*) emalloc(sizeof(property_reference)); + if (dynam_prop) { + reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC; + reference->prop.name = Z_STRVAL_P(propname); + reference->prop.name_length = Z_STRLEN_P(propname); + reference->prop.h = zend_get_hash_value(name_str, name_len+1); + reference->prop.doc_comment = NULL; + reference->prop.ce = ce; + } else { + reference->prop = *property_info; + } reference->ce = ce; - reference->prop = *property_info; intern->ptr = reference; intern->free_ptr = 1; intern->ce = ce; @@ -3897,7 +3936,7 @@ static void _property_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) Returns whether this property is public */ ZEND_METHOD(reflection_property, isPublic) { - _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC); + _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC); } /* }}} */ @@ -3959,7 +3998,7 @@ ZEND_METHOD(reflection_property, getValue) METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); - if (!(ref->prop.flags & ZEND_ACC_PUBLIC)) { + if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC))) { _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); @@ -4081,7 +4120,7 @@ ZEND_METHOD(reflection_property, getDeclaringClass) prop_name_len = strlen(prop_name); ce = tmp_ce = ref->ce; while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) { - if (tmp_info->flags & ZEND_ACC_PRIVATE) { + if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) { /* it's a private property, so it can't be inherited */ break; } @@ -4908,7 +4947,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.50 2008/03/13 15:56:21 iliaa Exp $"); + php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.164.2.33.2.55 2008/12/31 11:17:42 sebastian Exp $"); php_info_print_table_end(); } /* }}} */ diff --git a/ext/reflection/php_reflection.h b/ext/reflection/php_reflection.h index f7ff5fe4c..147054be6 100644 --- a/ext/reflection/php_reflection.h +++ b/ext/reflection/php_reflection.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.h,v 1.4.2.3.2.3 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: php_reflection.h,v 1.4.2.3.2.4 2008/12/31 11:17:43 sebastian Exp $ */ #ifndef PHP_REFLECTION_H #define PHP_REFLECTION_H diff --git a/ext/reflection/tests/001.phpt b/ext/reflection/tests/001.phpt index 55458885c..8e4a48729 100755 --- a/ext/reflection/tests/001.phpt +++ b/ext/reflection/tests/001.phpt @@ -1,91 +1,91 @@ ---TEST--
-Reflection inheritance
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class ReflectionClassEx extends ReflectionClass
-{
- public $bla;
-
- function getMethodNames()
- {
- $res = array();
- foreach($this->getMethods() as $m)
- {
- $res[] = $m->class . '::' . $m->name;
- }
- return $res;
- }
-}
-
-$r = new ReflectionClassEx('ReflectionClassEx');
-
-$exp = array (
- 'UMLClass::__clone',
- 'UMLClass::export',
- 'UMLClass::__construct',
- 'UMLClass::__toString',
- 'UMLClass::getName',
- 'UMLClass::isInternal',
- 'UMLClass::isUserDefined',
- 'UMLClass::isInstantiable',
- 'UMLClass::getFileName',
- 'UMLClass::getStartLine',
- 'UMLClass::getEndLine',
- 'UMLClass::getDocComment',
- 'UMLClass::getConstructor',
- 'UMLClass::getMethod',
- 'UMLClass::getMethods',
- 'UMLClass::getProperty',
- 'UMLClass::getProperties',
- 'UMLClass::getConstants',
- 'UMLClass::getConstant',
- 'UMLClass::getInterfaces',
- 'UMLClass::isInterface',
- 'UMLClass::isAbstract',
- 'UMLClass::isFinal',
- 'UMLClass::getModifiers',
- 'UMLClass::isInstance',
- 'UMLClass::newInstance',
- 'UMLClass::getParentClass',
- 'UMLClass::isSubclassOf',
- 'UMLClass::getStaticProperties',
- 'UMLClass::getDefaultProperties',
- 'UMLClass::isIterateable',
- 'UMLClass::implementsInterface',
- 'UMLClass::getExtension',
- 'UMLClass::getExtensionName');
-
-$miss = array();
-
-$res = $r->getMethodNames();
-
-foreach($exp as $m)
-{
- if (!in_array($m, $exp))
- {
- $miss[] = $m;
- }
-}
-
-var_dump($miss);
-
-$props = array_keys(get_class_vars('ReflectionClassEx'));
-sort($props);
-var_dump($props);
-var_dump($r->name);
-?>
-===DONE===
---EXPECT--
-array(0) {
-}
-array(2) {
- [0]=>
- string(3) "bla"
- [1]=>
- string(4) "name"
-}
-string(17) "ReflectionClassEx"
-===DONE===
+--TEST-- +Reflection inheritance +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class ReflectionClassEx extends ReflectionClass +{ + public $bla; + + function getMethodNames() + { + $res = array(); + foreach($this->getMethods() as $m) + { + $res[] = $m->class . '::' . $m->name; + } + return $res; + } +} + +$r = new ReflectionClassEx('ReflectionClassEx'); + +$exp = array ( + 'UMLClass::__clone', + 'UMLClass::export', + 'UMLClass::__construct', + 'UMLClass::__toString', + 'UMLClass::getName', + 'UMLClass::isInternal', + 'UMLClass::isUserDefined', + 'UMLClass::isInstantiable', + 'UMLClass::getFileName', + 'UMLClass::getStartLine', + 'UMLClass::getEndLine', + 'UMLClass::getDocComment', + 'UMLClass::getConstructor', + 'UMLClass::getMethod', + 'UMLClass::getMethods', + 'UMLClass::getProperty', + 'UMLClass::getProperties', + 'UMLClass::getConstants', + 'UMLClass::getConstant', + 'UMLClass::getInterfaces', + 'UMLClass::isInterface', + 'UMLClass::isAbstract', + 'UMLClass::isFinal', + 'UMLClass::getModifiers', + 'UMLClass::isInstance', + 'UMLClass::newInstance', + 'UMLClass::getParentClass', + 'UMLClass::isSubclassOf', + 'UMLClass::getStaticProperties', + 'UMLClass::getDefaultProperties', + 'UMLClass::isIterateable', + 'UMLClass::implementsInterface', + 'UMLClass::getExtension', + 'UMLClass::getExtensionName'); + +$miss = array(); + +$res = $r->getMethodNames(); + +foreach($exp as $m) +{ + if (!in_array($m, $exp)) + { + $miss[] = $m; + } +} + +var_dump($miss); + +$props = array_keys(get_class_vars('ReflectionClassEx')); +sort($props); +var_dump($props); +var_dump($r->name); +?> +===DONE=== +--EXPECT-- +array(0) { +} +array(2) { + [0]=> + string(3) "bla" + [1]=> + string(4) "name" +} +string(17) "ReflectionClassEx" +===DONE=== diff --git a/ext/reflection/tests/002.phpt b/ext/reflection/tests/002.phpt index 9b233d372..e522ac807 100755 --- a/ext/reflection/tests/002.phpt +++ b/ext/reflection/tests/002.phpt @@ -1,65 +1,65 @@ ---TEST--
-Reflection properties are read only
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class ReflectionMethodEx extends ReflectionMethod
-{
- public $foo = "xyz";
-
- function __construct($c,$m)
- {
- echo __METHOD__ . "\n";
- parent::__construct($c,$m);
- }
-}
-
-$r = new ReflectionMethodEx('ReflectionMethodEx','getName');
-
-var_dump($r->class);
-var_dump($r->name);
-var_dump($r->foo);
-@var_dump($r->bar);
-
-try
-{
- $r->class = 'bullshit';
-}
-catch(ReflectionException $e)
-{
- echo $e->getMessage() . "\n";
-}
-try
-{
-$r->name = 'bullshit';
-}
-catch(ReflectionException $e)
-{
- echo $e->getMessage() . "\n";
-}
-
-$r->foo = 'bar';
-$r->bar = 'baz';
-
-var_dump($r->class);
-var_dump($r->name);
-var_dump($r->foo);
-var_dump($r->bar);
-
-?>
-===DONE===
---EXPECTF--
-ReflectionMethodEx::__construct
-string(18) "ReflectionMethodEx"
-string(7) "getName"
-string(3) "xyz"
-NULL
-Cannot set read-only property ReflectionMethodEx::$class
-Cannot set read-only property ReflectionMethodEx::$name
-string(18) "ReflectionMethodEx"
-string(7) "getName"
-string(3) "bar"
-string(3) "baz"
-===DONE===
+--TEST-- +Reflection properties are read only +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class ReflectionMethodEx extends ReflectionMethod +{ + public $foo = "xyz"; + + function __construct($c,$m) + { + echo __METHOD__ . "\n"; + parent::__construct($c,$m); + } +} + +$r = new ReflectionMethodEx('ReflectionMethodEx','getName'); + +var_dump($r->class); +var_dump($r->name); +var_dump($r->foo); +@var_dump($r->bar); + +try +{ + $r->class = 'bullshit'; +} +catch(ReflectionException $e) +{ + echo $e->getMessage() . "\n"; +} +try +{ +$r->name = 'bullshit'; +} +catch(ReflectionException $e) +{ + echo $e->getMessage() . "\n"; +} + +$r->foo = 'bar'; +$r->bar = 'baz'; + +var_dump($r->class); +var_dump($r->name); +var_dump($r->foo); +var_dump($r->bar); + +?> +===DONE=== +--EXPECTF-- +ReflectionMethodEx::__construct +string(18) "ReflectionMethodEx" +string(7) "getName" +string(3) "xyz" +NULL +Cannot set read-only property ReflectionMethodEx::$class +Cannot set read-only property ReflectionMethodEx::$name +string(18) "ReflectionMethodEx" +string(7) "getName" +string(3) "bar" +string(3) "baz" +===DONE=== diff --git a/ext/reflection/tests/004.phpt b/ext/reflection/tests/004.phpt index 912d52654..362cbcecd 100755 --- a/ext/reflection/tests/004.phpt +++ b/ext/reflection/tests/004.phpt @@ -1,44 +1,44 @@ ---TEST--
-ReflectionMethod::invoke() with non object or null value
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class a {
- function a(){
- }
-}
-class b {
-}
-
-$b = new b();
-
-$a=new ReflectionClass("a");
-$m=$a->getMethod("a");
-
-try {
- $m->invoke(null);
-} catch (ReflectionException $E) {
- echo $E->getMessage()."\n";
-}
-
-
-try {
- $m->invoke($b);
-} catch (ReflectionException $E) {
- echo $E->getMessage()."\n";
-}
-
-$b = new a();
-try {
- $m->invoke($b);
-} catch (ReflectionException $E) {
- echo $E->getMessage()."\n";
-}
-
-echo "===DONE===\n";?>
---EXPECT--
-Non-object passed to Invoke()
-Given object is not an instance of the class this method was declared in
-===DONE===
+--TEST-- +ReflectionMethod::invoke() with non object or null value +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class a { + function a(){ + } +} +class b { +} + +$b = new b(); + +$a=new ReflectionClass("a"); +$m=$a->getMethod("a"); + +try { + $m->invoke(null); +} catch (ReflectionException $E) { + echo $E->getMessage()."\n"; +} + + +try { + $m->invoke($b); +} catch (ReflectionException $E) { + echo $E->getMessage()."\n"; +} + +$b = new a(); +try { + $m->invoke($b); +} catch (ReflectionException $E) { + echo $E->getMessage()."\n"; +} + +echo "===DONE===\n";?> +--EXPECT-- +Non-object passed to Invoke() +Given object is not an instance of the class this method was declared in +===DONE=== diff --git a/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt new file mode 100644 index 000000000..3bf8f77ec --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt @@ -0,0 +1,198 @@ +--TEST-- +ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + + +class A { + static public $statPubC = "stat pubC in A"; + static protected $statProtC = "stat protC in A"; + static private $statPrivC = "stat privC in A"; + + static public $statPubA = "stat pubA in A"; + static protected $statProtA = "stat protA in A"; + static private $statPrivA = "stat privA in A"; + + public $pubC = "pubC in A"; + protected $protC = "protC in A"; + private $privC = "privC in A"; + + public $pubA = "pubA in A"; + protected $protA = "protA in A"; + private $privA = "privA in A"; +} + +class B extends A { + static public $statPubC = "stat pubC in B"; + static protected $statProtC = "stat protC in B"; + static private $statPrivC = "stat privC in B"; + + static public $statPubB = "stat pubB in B"; + static protected $statProtB = "stat protB in B"; + static private $statPrivB = "stat privB in B"; + + public $pubC = "pubC in B"; + protected $protC = "protC in B"; + private $privC = "privC in B"; + + public $pubB = "pubB in B"; + protected $protB = "protB in B"; + private $privB = "privB in B"; +} + +class C extends B { + static public $statPubC = "stat pubC in C"; + static protected $statProtC = "stat protC in C"; + static private $statPrivC = "stat privC in C"; + + public $pubC = "pubC in C"; + protected $protC = "protC in C"; + private $privC = "privC in C"; +} + +class X { + static public $statPubC = "stat pubC in X"; + static protected $statProtC = "stat protC in X"; + static private $statPrivC = "stat privC in X"; + + public $pubC = "pubC in X"; + protected $protC = "protC in X"; + private $privC = "privC in X"; +} + +$classes = array('A', 'B', 'C', 'X'); +foreach ($classes as $class) { + $rc = new ReflectionClass($class); + echo "\n\n---- Static properties in $class ----\n"; + print_r($rc->getStaticProperties()); + echo "\n\n---- Default properties in $class ----\n"; + print_r($rc->getDefaultProperties()); +} + +?> +--EXPECTF-- +---- Static properties in A ---- +Array +( + [statPubC] => stat pubC in A + [statProtC] => stat protC in A + [statPrivC] => stat privC in A + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in A ---- +Array +( + [statPubC] => stat pubC in A + [statProtC] => stat protC in A + [statPrivC] => stat privC in A + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A + [pubC] => pubC in A + [protC] => protC in A + [privC] => privC in A + [pubA] => pubA in A + [protA] => protA in A + [privA] => privA in A +) + + +---- Static properties in B ---- +Array +( + [statPubC] => stat pubC in B + [statProtC] => stat protC in B + [statPrivC] => stat privC in A + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in B ---- +Array +( + [statPubC] => stat pubC in B + [statProtC] => stat protC in B + [statPrivC] => stat privC in B + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [pubC] => pubC in B + [protC] => protC in B + [privC] => privC in B + [pubB] => pubB in B + [protB] => protB in B + [privB] => privB in B + [pubA] => pubA in A + [protA] => protA in A +) + + +---- Static properties in C ---- +Array +( + [statPubC] => stat pubC in C + [statProtC] => stat protC in C + [statPrivC] => stat privC in A + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in C ---- +Array +( + [statPubC] => stat pubC in C + [statProtC] => stat protC in C + [statPrivC] => stat privC in C + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [pubC] => pubC in C + [protC] => protC in C + [privC] => privC in C + [pubB] => pubB in B + [protB] => protB in B + [pubA] => pubA in A + [protA] => protA in A +) + + +---- Static properties in X ---- +Array +( + [statPubC] => stat pubC in X + [statProtC] => stat protC in X + [statPrivC] => stat privC in X +) + + +---- Default properties in X ---- +Array +( + [statPubC] => stat pubC in X + [statProtC] => stat protC in X + [statPrivC] => stat privC in X + [pubC] => pubC in X + [protC] => protC in X + [privC] => privC in X +) + diff --git a/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt b/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt new file mode 100644 index 000000000..6012f0855 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt @@ -0,0 +1,45 @@ +--TEST-- +ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() - wrong param count +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +interface I {} +class C implements I {} +$rc = new ReflectionClass('C'); +var_dump($rc->getDefaultProperties(null)); +var_dump($rc->getDefaultProperties('X')); +var_dump($rc->getDefaultProperties(true)); +var_dump($rc->getDefaultProperties(array(1,2,3))); +var_dump($rc->getStaticProperties(null)); +var_dump($rc->getStaticProperties('X')); +var_dump($rc->getStaticProperties(true)); +var_dump($rc->getStaticProperties(array(1,2,3))); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 8 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 10 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 11 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 12 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt new file mode 100644 index 000000000..5feb560ae --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::getDocComment() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +/** + + + My +Doc + * Comment +for A + +* */ +class A {} + +/** My DocComment for B */ +class B extends A { } + +class C extends B {} + +/** + * Interface doc comment + */ + + + + +interface I {} + +/*.* + * Not a doc comment + */ +class D implements I {} + +/**** Not a doc comment */ +class E extends C implements I {} {} + +/**?** Not a doc comment */ +class F extends C implements I {} {} + +/** ** Doc comment for G */ +final class G extends C implements I {} {} + +$classes = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'I'); +foreach ($classes as $class) { + echo "\n\n---> Doc comment for class $class:\n"; + $rc = new ReflectionClass($class); + var_dump($rc->getDocComment()); +} + + +?> +--EXPECTF-- + + +---> Doc comment for class A: +string(%d) "/** + + + My +Doc + * Comment +for A + +* */" + + +---> Doc comment for class B: +string(26) "/** My DocComment for B */" + + +---> Doc comment for class C: +bool(false) + + +---> Doc comment for class D: +bool(false) + + +---> Doc comment for class E: +bool(false) + + +---> Doc comment for class F: +bool(false) + + +---> Doc comment for class G: +string(27) "/** ** Doc comment for G */" + + +---> Doc comment for class I: +string(%d) "/** + * Interface doc comment + */"
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt new file mode 100644 index 000000000..6668a8b65 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::getDocComment() - bad params +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C {} +$rc = new ReflectionClass('C'); +var_dump($rc->getDocComment(null)); +var_dump($rc->getDocComment('X')); +var_dump($rc->getDocComment(true)); +var_dump($rc->getDocComment(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 7 +NULL diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt new file mode 100644 index 000000000..42136003e --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt @@ -0,0 +1,311 @@ +--TEST-- +ReflectionClass::getInterfaces() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A0 {} +class B0 extends A0 {} +abstract class A1 {} +class B1 extends A1 {} + +interface I0 {} +interface I1 {} +interface I2 {} +interface I3 {} +interface I4 extends I3 {} +interface I5 extends I4 {} +interface I6 extends I5, I1, I2 {} +interface I7 extends I6 {} + +class C0 implements I0 {} +class C1 implements I1, I3 {} +class C2 extends C1 {} +class C3 extends C2 implements I1 {} +class C4 extends C3 implements I2 {} +class C5 extends C4 implements I7 {} +class C6 implements I1, I2, I3, I4, I5, I6, I7 {} + + +$classes = array( 'A0', 'A1', 'B0', 'B1', + 'I0', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', + 'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6' ); + +foreach ($classes as $class) { + echo "---( Interfaces implemented by $class )---\n "; + $rc = new ReflectionClass($class); + $interfaces = $rc->getInterfaces(); + // Sort interfaces so that tests do not fail because of wrong order. + ksort($interfaces); + print_r($interfaces); +} + +?> +--EXPECTF-- +---( Interfaces implemented by A0 )--- + Array +( +) +---( Interfaces implemented by A1 )--- + Array +( +) +---( Interfaces implemented by B0 )--- + Array +( +) +---( Interfaces implemented by B1 )--- + Array +( +) +---( Interfaces implemented by I0 )--- + Array +( +) +---( Interfaces implemented by I1 )--- + Array +( +) +---( Interfaces implemented by I2 )--- + Array +( +) +---( Interfaces implemented by I3 )--- + Array +( +) +---( Interfaces implemented by I4 )--- + Array +( + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by I5 )--- + Array +( + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + +) +---( Interfaces implemented by I6 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + +) +---( Interfaces implemented by I7 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + +) +---( Interfaces implemented by C0 )--- + Array +( + [I0] => ReflectionClass Object + ( + [name] => I0 + ) + +) +---( Interfaces implemented by C1 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C2 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C3 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C4 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C5 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I7] => ReflectionClass Object + ( + [name] => I7 + ) + +) +---( Interfaces implemented by C6 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I7] => ReflectionClass Object + ( + [name] => I7 + ) + +) diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt new file mode 100644 index 000000000..328a7c3e6 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt @@ -0,0 +1,53 @@ +--TEST-- +ReflectionClass::getInterfaces() - interface ordering. +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +interface I1 {} +interface I2 {} +interface I3 {} +interface I4 extends I3 {} +interface I5 extends I4 {} +interface I6 extends I5, I1, I2 {} +interface I7 extends I6 {} + +$rc = new ReflectionClass('I7'); +$interfaces = $rc->getInterfaces(); +print_r($interfaces); +?> +--EXPECTF-- +Array +( + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + +)
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt new file mode 100644 index 000000000..74044f753 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt @@ -0,0 +1,69 @@ +--TEST-- +ReflectionClass::getInterfaces() - odd ampersand behaviour. +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +echo "An object is in an array and is referenced. As expected, var_dumping the array shows '&':\n"; +$a = array(new stdclass); +$b =& $a[0]; +var_dump($a); + +echo "Naturally, this remains true if we modify the object:\n"; +$a[0]->x = 1; +var_dump($a); + + +echo "\n\nObtain the array of interfaces implemented by C.\n"; +interface I {} +class C implements I {} +$rc = new ReflectionClass('C'); +$a = $rc->getInterfaces(); +echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n"; +echo "Var_dumping this array shows that the elements are referenced. By what?\n"; +var_dump($a); + +echo "Modify the object, and it is apparently no longer referenced.\n"; +$a['I']->x = 1; +var_dump($a); + +?> +--EXPECTF-- +An object is in an array and is referenced. As expected, var_dumping the array shows '&': +array(1) { + [0]=> + &object(stdClass)#%d (0) { + } +} +Naturally, this remains true if we modify the object: +array(1) { + [0]=> + &object(stdClass)#%d (1) { + ["x"]=> + int(1) + } +} + + +Obtain the array of interfaces implemented by C. +The result is an array in which each element is an object (an instance of ReflectionClass) +Var_dumping this array shows that the elements are referenced. By what? +array(1) { + ["I"]=> + &object(ReflectionClass)#%d (1) { + ["name"]=> + string(1) "I" + } +} +Modify the object, and it is apparently no longer referenced. +array(1) { + ["I"]=> + object(ReflectionClass)#%d (2) { + ["name"]=> + string(1) "I" + ["x"]=> + int(1) + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt new file mode 100644 index 000000000..5f42e4736 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionClass::getInterfaces() - wrong param count +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +interface I {} +class C implements I {} +$rc = new ReflectionClass('C'); +var_dump($rc->getInterfaces(null)); +var_dump($rc->getInterfaces('X')); +var_dump($rc->getInterfaces(true)); +var_dump($rc->getInterfaces(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 8 +NULL diff --git a/ext/reflection/tests/ReflectionClass_getMethod_001.phpt b/ext/reflection/tests/ReflectionClass_getMethod_001.phpt new file mode 100644 index 000000000..5821ebad0 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethod_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +ReflectionClass::getMethod() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public function f() {} + static public function s() {} +} +class subpubf extends pubf { +} + +class protf { + protected function f() {} + static protected function s() {} +} +class subprotf extends protf { +} + +class privf { + private function f() {} + static private function s() {} +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + echo " --> Check for f(): "; + var_dump($rc->getMethod("f")); + echo " --> Check for s(): "; + var_dump($rc->getMethod("s")); + echo " --> Check for F(): "; + var_dump($rc->getMethod("F")); + echo " --> Check for doesntExist(): "; + try { + var_dump($rc->getMethod("doesntExist")); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subpubf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class protf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subprotf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class privf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subprivf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" +} + --> Check for doesntExist(): Method doesntExist does not exist
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethod_002.phpt b/ext/reflection/tests/ReflectionClass_getMethod_002.phpt new file mode 100644 index 000000000..2baabdeda --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethod_002.phpt @@ -0,0 +1,74 @@ +--TEST-- +ReflectionClass::getMethod() - error cases +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + function f() {} +} + +$rc = new ReflectionClass("C"); +echo "Check invalid params:\n"; +try { + var_dump($rc->getMethod()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod("f", "f")); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(1)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(1.5)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(true)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(array(1,2,3))); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(new C)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 0 given in %s on line 9 +NULL + +Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 2 given in %s on line 14 +NULL +Method does not exist +Method 1 does not exist +Method 1.5 does not exist +Method 1 does not exist + +Warning: ReflectionClass::getMethod() expects parameter 1 to be string, array given in %s on line 39 +NULL + +Warning: ReflectionClass::getMethod() expects parameter 1 to be string, object given in %s on line 44 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt new file mode 100644 index 000000000..867d669ad --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt @@ -0,0 +1,140 @@ +--TEST-- +ReflectionClass::getMethods() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public function f() {} + static public function s() {} +} +class subpubf extends pubf { +} + +class protf { + protected function f() {} + static protected function s() {} +} +class subprotf extends protf { +} + +class privf { + private function f() {} + static private function s() {} +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + var_dump($rc->getMethods()); +} + +?> +--EXPECTF-- +Reflecting on class pubf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" + } +} +Reflecting on class subpubf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" + } +} +Reflecting on class protf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" + } +} +Reflecting on class subprotf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" + } +} +Reflecting on class privf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" + } +} +Reflecting on class subprivf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethods_002.phpt b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt new file mode 100644 index 000000000..b25222563 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt @@ -0,0 +1,18 @@ +--TEST-- +ReflectionClass::getMethods() - invalid arguments +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +$rc = new ReflectionClass("ReflectionClass"); +echo "\nTest invalid arguments:"; +$rc->getMethods('X'); +$rc->getMethods('X', true); + +?> +--EXPECTF-- +Test invalid arguments: +Warning: ReflectionClass::getMethods() expects parameter 1 to be long, string given in %s on line 4 + +Warning: ReflectionClass::getMethods() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt new file mode 100644 index 000000000..435f5d2d8 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt @@ -0,0 +1,191 @@ +--TEST-- +ReflectionClass::getMethods() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public function pubf1() {} + public function pubf2() {} + private function privf1() {} + private function privf2() {} + static public function pubsf1() {} + static public function pubsf2() {} + static private function privsf1() {} + static private function privsf2() {} +} + +$rc = new ReflectionClass("C"); +$StaticFlag = 0x01; +$pubFlag = 0x100; +$privFlag = 0x400; + +echo "No methods:"; +var_dump($rc->getMethods(0)); + +echo "Public methods:"; +var_dump($rc->getMethods($pubFlag)); + +echo "Private methods:"; +var_dump($rc->getMethods($privFlag)); + +echo "Public or static methods:"; +var_dump($rc->getMethods($StaticFlag | $pubFlag)); + +echo "Private or static methods:"; +var_dump($rc->getMethods($StaticFlag | $privFlag)); + + +?> +--EXPECTF-- +No methods:array(0) { +} +Public methods:array(4) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } +} +Private methods:array(4) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} +Public or static methods:array(6) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} +Private or static methods:array(6) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} diff --git a/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt b/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt new file mode 100644 index 000000000..e26595a87 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionClass::getParentClass() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A {} +class B extends A {} + +$rc = new ReflectionClass('B'); +$parent = $rc->getParentClass(); +$grandParent = $parent->getParentClass(); +var_dump($parent, $grandParent); + +echo "\nTest bad params:\n"; +var_dump($rc->getParentClass(null)); +var_dump($rc->getParentClass('x')); +var_dump($rc->getParentClass('x', 123)); + +?> +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(1) "A" +} +bool(false) + +Test bad params: + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 11 +NULL + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 12 +NULL + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 13 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt new file mode 100644 index 000000000..5eecc5dee --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt @@ -0,0 +1,126 @@ +--TEST-- +ReflectionClass::getProperties() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public $a; + static public $s; +} +class subpubf extends pubf { +} + +class protf { + protected $a; + static protected $s; +} +class subprotf extends protf { +} + +class privf { + private $a; + static private $s; +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + var_dump($rc->getProperties()); +} + +?> +--EXPECTF-- +Reflecting on class pubf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "pubf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" + } +} +Reflecting on class subpubf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(7) "subpubf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" + } +} +Reflecting on class protf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "protf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" + } +} +Reflecting on class subprotf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(8) "subprotf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" + } +} +Reflecting on class privf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "privf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" + } +} +Reflecting on class subprivf: +array(0) { +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperties_002.phpt b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt new file mode 100644 index 000000000..c21cff24f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getProperties() - invalid arguments +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +$rc = new ReflectionClass("ReflectionClass"); +echo "\nTest invalid arguments:"; +$rc->getProperties('X'); +$rc->getProperties('X', true); +?> +--EXPECTF-- +Test invalid arguments: +Warning: ReflectionClass::getProperties() expects parameter 1 to be long, string given in %s on line 4 + +Warning: ReflectionClass::getProperties() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt new file mode 100644 index 000000000..b4f9a774d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt @@ -0,0 +1,189 @@ +--TEST-- +ReflectionClass::getProperties() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public $pub1; + public $pub2; + private $priv1; + private $priv2; + static public $pubs; + static public $pubs2; + static private $privs1; + static private $privs2; +} + +$rc = new ReflectionClass("C"); +$StaticFlag = 0x01; +$pubFlag = 0x100; +$privFlag = 0x400; + +echo "No properties:"; +var_dump($rc->getProperties(0)); + +echo "Public properties:"; +var_dump($rc->getProperties($pubFlag)); + +echo "Private properties:"; +var_dump($rc->getProperties($privFlag)); + +echo "Public or static properties:"; +var_dump($rc->getProperties($StaticFlag | $pubFlag)); + +echo "Private or static properties:"; +var_dump($rc->getProperties($StaticFlag | $privFlag)); +?> +--EXPECTF-- +No properties:array(0) { +} +Public properties:array(4) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } +} +Private properties:array(4) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +} +Public or static properties:array(6) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +} +Private or static properties:array(6) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_001.phpt b/ext/reflection/tests/ReflectionClass_getProperty_001.phpt new file mode 100644 index 000000000..fa5deaa67 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_001.phpt @@ -0,0 +1,146 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public $a; + static public $s; +} +class subpubf extends pubf { +} + +class protf { + protected $a; + static protected $s; +} +class subprotf extends protf { +} + +class privf { + private $a; + static protected $s; +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + try { + echo " --> Check for s: "; + var_dump($rc->getProperty("s")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for a: "; + var_dump($rc->getProperty("a")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for A: "; + var_dump($rc->getProperty("A")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for doesntExist: "; + var_dump($rc->getProperty("doesntExist")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "pubf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subpubf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(7) "subpubf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class protf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "protf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subprotf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(8) "subprotf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class privf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "privf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subprivf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" +} + --> Check for a: Property a does not exist + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_002.phpt b/ext/reflection/tests/ReflectionClass_getProperty_002.phpt new file mode 100644 index 000000000..be7bb53bc --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_002.phpt @@ -0,0 +1,72 @@ +--TEST-- +ReflectionClass::getProperty() - error cases +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public $a; +} + +$rc = new ReflectionClass("C"); +echo "Check invalid params:\n"; +try { + var_dump($rc->getProperty()); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty("a", "a")); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(null)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(1)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(1.5)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(true)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(array(1,2,3))); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(new C)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 0 given in %s on line 9 +NULL + +Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 2 given in %s on line 14 +NULL +Property does not exist +Property 1 does not exist +Property 1.5 does not exist +Property 1 does not exist + +Warning: ReflectionClass::getProperty() expects parameter 1 to be string, array given in %s on line 39 +NULL + +Warning: ReflectionClass::getProperty() expects parameter 1 to be string, object given in %s on line 44 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_003.phpt b/ext/reflection/tests/ReflectionClass_getProperty_003.phpt new file mode 100644 index 000000000..dddd2260f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_003.phpt @@ -0,0 +1,251 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + static public $pubC = "pubC in A"; + static protected $protC = "protC in A"; + static private $privC = "privC in A"; + + static public $pubA = "pubA in A"; + static protected $protA = "protA in A"; + static private $privA = "privA in A"; +} + +class B extends A { + static public $pubC = "pubC in B"; + static protected $protC = "protC in B"; + static private $privC = "privC in B"; + + static public $pubB = "pubB in B"; + static protected $protB = "protB in B"; + static private $privB = "privB in B"; +} + +class C extends B { + static public $pubC = "pubC in C"; + static protected $protC = "protC in C"; + static private $privC = "privC in C"; +} + +class X { + static public $pubC = "pubC in X"; + static protected $protC = "protC in X"; + static private $privC = "privC in X"; +} + +$myC = new C; +$rc = new ReflectionClass("C"); + +function showInfo($name) { + global $rc, $myC; + echo "--- (Reflecting on $name) ---\n"; + try { + $rp = $rc->getProperty($name); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } + try { + var_dump($rp); + var_dump($rp->getValue($myC)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } +} + + +showInfo("pubA"); +showInfo("protA"); +showInfo("privA"); + +showInfo("pubB"); +showInfo("protB"); +showInfo("privB"); + +showInfo("pubC"); +showInfo("protC"); +showInfo("privC"); +showInfo("doesntExist"); + +showInfo("A::pubC"); +showInfo("A::protC"); +showInfo("A::privC"); + +showInfo("B::pubC"); +showInfo("B::protC"); +showInfo("B::privC"); + +showInfo("c::pubC"); +showInfo("c::PUBC"); +showInfo("C::pubC"); +showInfo("C::protC"); +showInfo("C::privC"); + +showInfo("X::pubC"); +showInfo("X::protC"); +showInfo("X::privC"); +showInfo("X::doesntExist"); + +showInfo("doesntexist::doesntExist"); + +?> +--EXPECTF-- +--- (Reflecting on pubA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubA" + ["class"]=> + string(1) "C" +} +string(9) "pubA in A" +--- (Reflecting on protA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protA" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protA +--- (Reflecting on privA) --- +Property privA does not exist +--- (Reflecting on pubB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubB" + ["class"]=> + string(1) "C" +} +string(9) "pubB in B" +--- (Reflecting on protB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protB" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protB +--- (Reflecting on privB) --- +Property privB does not exist +--- (Reflecting on pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on doesntExist) --- +Property doesntExist does not exist +--- (Reflecting on A::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "A" +} +string(9) "pubC in A" +--- (Reflecting on A::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::protC +--- (Reflecting on A::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::privC +--- (Reflecting on B::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "B" +} +string(9) "pubC in B" +--- (Reflecting on B::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::protC +--- (Reflecting on B::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::privC +--- (Reflecting on c::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on c::PUBC) --- +Property PUBC does not exist +--- (Reflecting on C::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on C::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on C::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on X::pubC) --- +Fully qualified property name X::pubC does not specify a base class of C +--- (Reflecting on X::protC) --- +Fully qualified property name X::protC does not specify a base class of C +--- (Reflecting on X::privC) --- +Fully qualified property name X::privC does not specify a base class of C +--- (Reflecting on X::doesntExist) --- +Fully qualified property name X::doesntExist does not specify a base class of C +--- (Reflecting on doesntexist::doesntExist) --- +Class doesntexist does not exist
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_004.phpt b/ext/reflection/tests/ReflectionClass_getProperty_004.phpt new file mode 100644 index 000000000..791f5e1fa --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_004.phpt @@ -0,0 +1,251 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + public $pubC = "pubC in A"; + protected $protC = "protC in A"; + private $privC = "privC in A"; + + public $pubA = "pubA in A"; + protected $protA = "protA in A"; + private $privA = "privA in A"; +} + +class B extends A { + public $pubC = "pubC in B"; + protected $protC = "protC in B"; + private $privC = "privC in B"; + + public $pubB = "pubB in B"; + protected $protB = "protB in B"; + private $privB = "privB in B"; +} + +class C extends B { + public $pubC = "pubC in C"; + protected $protC = "protC in C"; + private $privC = "privC in C"; +} + +class X { + public $pubC = "pubC in X"; + protected $protC = "protC in X"; + private $privC = "privC in X"; +} + +$myC = new C; +$rc = new ReflectionClass("C"); + +function showInfo($name) { + global $rc, $myC; + echo "--- (Reflecting on $name) ---\n"; + try { + $rp = $rc->getProperty($name); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } + try { + var_dump($rp); + var_dump($rp->getValue($myC)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } +} + + +showInfo("pubA"); +showInfo("protA"); +showInfo("privA"); + +showInfo("pubB"); +showInfo("protB"); +showInfo("privB"); + +showInfo("pubC"); +showInfo("protC"); +showInfo("privC"); +showInfo("doesntExist"); + +showInfo("A::pubC"); +showInfo("A::protC"); +showInfo("A::privC"); + +showInfo("B::pubC"); +showInfo("B::protC"); +showInfo("B::privC"); + +showInfo("c::pubC"); +showInfo("c::PUBC"); +showInfo("C::pubC"); +showInfo("C::protC"); +showInfo("C::privC"); + +showInfo("X::pubC"); +showInfo("X::protC"); +showInfo("X::privC"); +showInfo("X::doesntExist"); + +showInfo("doesntexist::doesntExist"); + +?> +--EXPECTF-- +--- (Reflecting on pubA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubA" + ["class"]=> + string(1) "C" +} +string(9) "pubA in A" +--- (Reflecting on protA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protA" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protA +--- (Reflecting on privA) --- +Property privA does not exist +--- (Reflecting on pubB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubB" + ["class"]=> + string(1) "C" +} +string(9) "pubB in B" +--- (Reflecting on protB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protB" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protB +--- (Reflecting on privB) --- +Property privB does not exist +--- (Reflecting on pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on doesntExist) --- +Property doesntExist does not exist +--- (Reflecting on A::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "A" +} +string(9) "pubC in C" +--- (Reflecting on A::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::protC +--- (Reflecting on A::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::privC +--- (Reflecting on B::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "B" +} +string(9) "pubC in C" +--- (Reflecting on B::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::protC +--- (Reflecting on B::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::privC +--- (Reflecting on c::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on c::PUBC) --- +Property PUBC does not exist +--- (Reflecting on C::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on C::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on C::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on X::pubC) --- +Fully qualified property name X::pubC does not specify a base class of C +--- (Reflecting on X::protC) --- +Fully qualified property name X::protC does not specify a base class of C +--- (Reflecting on X::privC) --- +Fully qualified property name X::privC does not specify a base class of C +--- (Reflecting on X::doesntExist) --- +Fully qualified property name X::doesntExist does not specify a base class of C +--- (Reflecting on doesntexist::doesntExist) --- +Class doesntexist does not exist
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt new file mode 100644 index 000000000..733c4c7e4 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt @@ -0,0 +1,67 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + static private $privateOverridden = "original private"; + static protected $protectedOverridden = "original protected"; + static public $publicOverridden = "original public"; +} + +class B extends A { + static private $privateOverridden = "changed private"; + static protected $protectedOverridden = "changed protected"; + static public $publicOverridden = "changed public"; +} + +echo "Retrieving static values from A:\n"; +$rcA = new ReflectionClass('A'); +var_dump($rcA->getStaticPropertyValue("privateOverridden", "default value")); +var_dump($rcA->getStaticPropertyValue("\0A\0privateOverridden")); +var_dump($rcA->getStaticPropertyValue("protectedOverridden", "default value")); +var_dump($rcA->getStaticPropertyValue("\0*\0protectedOverridden")); +var_dump($rcA->getStaticPropertyValue("publicOverridden")); + +echo "\nRetrieving static values from B:\n"; +$rcB = new ReflectionClass('B'); +var_dump($rcB->getStaticPropertyValue("\0A\0privateOverridden")); +var_dump($rcB->getStaticPropertyValue("\0B\0privateOverridden")); +var_dump($rcB->getStaticPropertyValue("\0*\0protectedOverridden")); +var_dump($rcB->getStaticPropertyValue("publicOverridden")); + +echo "\nRetrieving non-existent values from A with no default value:\n"; +try { + var_dump($rcA->getStaticPropertyValue("protectedOverridden")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump($rcA->getStaticPropertyValue("privateOverridden")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +Retrieving static values from A: +string(13) "default value" +string(16) "original private" +string(13) "default value" +string(18) "original protected" +string(15) "original public" + +Retrieving static values from B: +string(16) "original private" +string(15) "changed private" +string(17) "changed protected" +string(14) "changed public" + +Retrieving non-existent values from A with no default value: +Class A does not have a property named protectedOverridden +Class A does not have a property named privateOverridden diff --git a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt new file mode 100644 index 000000000..36b4744d8 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt @@ -0,0 +1,52 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() - bad params +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public static $x; +} + +$rc = new ReflectionClass('C'); +try { + var_dump($rc->getStaticPropertyValue("x", "default value", 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(1.5, 'def')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(array(1,2,3))); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- + +Warning: ReflectionClass::getStaticPropertyValue() expects at most 2 parameters, 3 given in %s on line 8 +NULL + +Warning: ReflectionClass::getStaticPropertyValue() expects at least 1 parameter, 0 given in %s on line 13 +NULL +Class C does not have a property named +string(3) "def" + +Warning: ReflectionClass::getStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 28 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt b/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt new file mode 100644 index 000000000..6e6d4341c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionClass::hasConstant() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + const myConst = 1; +} + +class D extends C { +} + + +$rc = new ReflectionClass("C"); +echo "Check existing constant: "; +var_dump($rc->hasConstant("myConst")); +echo "Check existing constant, different case: "; +var_dump($rc->hasConstant("MyCoNsT")); +echo "Check absent constant: "; +var_dump($rc->hasConstant("doesntExist")); + + +$rd = new ReflectionClass("D"); +echo "Check inherited constant: "; +var_dump($rd->hasConstant("myConst")); +echo "Check absent constant: "; +var_dump($rd->hasConstant("doesntExist")); +?> +--EXPECTF-- +Check existing constant: bool(true) +Check existing constant, different case: bool(false) +Check absent constant: bool(false) +Check inherited constant: bool(true) +Check absent constant: bool(false)
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt b/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt new file mode 100644 index 000000000..a0a76f024 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasConstant() - error cases +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + const myConst = 1; +} + +$rc = new ReflectionClass("C"); +echo "Check invalid params:\n"; +var_dump($rc->hasConstant()); +var_dump($rc->hasConstant("myConst", "myConst")); +var_dump($rc->hasConstant(null)); +var_dump($rc->hasConstant(1)); +var_dump($rc->hasConstant(1.5)); +var_dump($rc->hasConstant(true)); +var_dump($rc->hasConstant(array(1,2,3))); +var_dump($rc->hasConstant(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasConstant() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasConstant() 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_hasMethod_001.phpt b/ext/reflection/tests/ReflectionClass_hasMethod_001.phpt new file mode 100644 index 000000000..81614bd9f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasMethod_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::hasMethod() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public function f() {} + static public function s() {} +} +class subpubf extends pubf { +} + +class protf { + protected function f() {} + static protected function s() {} +} +class subprotf extends protf { +} + +class privf { + private function f() {} + static private function s() {} +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + echo " --> Check for f(): "; + var_dump($rc->hasMethod("f")); + echo " --> Check for s(): "; + var_dump($rc->hasMethod("s")); + echo " --> Check for F(): "; + var_dump($rc->hasMethod("F")); + echo " --> Check for doesntExist(): "; + var_dump($rc->hasMethod("doesntExist")); +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subpubf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class protf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subprotf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class privf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subprivf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt b/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt new file mode 100644 index 000000000..63fe8791f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasMethod() - error cases +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + function f() {} +} + +$rc = new ReflectionClass("C"); +echo "Check invalid params:\n"; +var_dump($rc->hasMethod()); +var_dump($rc->hasMethod("f", "f")); +var_dump($rc->hasMethod(null)); +var_dump($rc->hasMethod(1)); +var_dump($rc->hasMethod(1.5)); +var_dump($rc->hasMethod(true)); +var_dump($rc->hasMethod(array(1,2,3))); +var_dump($rc->hasMethod(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, object given in %s on line 15 +NULL diff --git a/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt b/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt new file mode 100644 index 000000000..94f739c33 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::hasProperty() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class pubf { + public $a; + static public $s; +} +class subpubf extends pubf { +} + +class protf { + protected $a; + static protected $s; +} +class subprotf extends protf { +} + +class privf { + private $a; + static protected $s; +} +class subprivf extends privf { +} + +$classes = array("pubf", "subpubf", "protf", "subprotf", + "privf", "subprivf"); +foreach($classes as $class) { + echo "Reflecting on class $class: \n"; + $rc = new ReflectionClass($class); + echo " --> Check for s: "; + var_dump($rc->hasProperty("s")); + echo " --> Check for a: "; + var_dump($rc->hasProperty("a")); + echo " --> Check for A: "; + var_dump($rc->hasProperty("A")); + echo " --> Check for doesntExist: "; + var_dump($rc->hasProperty("doesntExist")); +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subpubf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class protf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subprotf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class privf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subprivf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) + diff --git a/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt b/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt new file mode 100644 index 000000000..753890394 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasProperty() - error cases +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public $a; +} + +$rc = new ReflectionClass("C"); +echo "Check invalid params:\n"; +var_dump($rc->hasProperty()); +var_dump($rc->hasProperty("a", "a")); +var_dump($rc->hasProperty(null)); +var_dump($rc->hasProperty(1)); +var_dump($rc->hasProperty(1.5)); +var_dump($rc->hasProperty(true)); +var_dump($rc->hasProperty(array(1,2,3))); +var_dump($rc->hasProperty(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, object given in %s on line 15 +NULL diff --git a/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt b/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt new file mode 100644 index 000000000..9c2fdeddd --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt @@ -0,0 +1,155 @@ +--TEST-- +ReflectionClass::implementsInterface() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +interface I1 {} +class A implements I1 {} +class B extends A {} + +interface I2 extends I1 {} +class C implements I2 {} + +$classNames = array('A', 'B', 'C', 'I1', 'I2'); + +foreach ($classNames as $className) { + $rcs[$className] = new ReflectionClass($className); +} + +foreach ($rcs as $childName => $child) { + foreach ($rcs as $parentName => $parent) { + echo "Does " . $childName . " implement " . $parentName . "? \n"; + echo " - Using object argument: "; + try { + var_dump($child->implementsInterface($parent)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + echo " - Using string argument: "; + try { + var_dump($child->implementsInterface($parentName)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + } +} + + + +echo "\n\nTest bad arguments:\n"; +try { + var_dump($rcs['A']->implementsInterface()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Does A implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does A implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does A implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does A implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does A implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does B implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does B implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does B implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does B implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does B implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does C implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does C implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does C implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does C implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does C implement I2? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I1 implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does I1 implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does I1 implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does I1 implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I1 implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does I2 implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does I2 implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does I2 implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does I2 implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I2 implement I2? + - Using object argument: bool(true) + - Using string argument: bool(true) + + +Test bad arguments: + +Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given in %s on line 37 +NULL + +Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given in %s on line 42 +NULL +Parameter one must either be a string or a ReflectionClass object +Interface ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object diff --git a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt new file mode 100644 index 000000000..3ece91542 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::isIterateable() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +Interface ExtendsIterator extends Iterator { +} +Interface ExtendsIteratorAggregate extends IteratorAggregate { +} +Class IteratorImpl implements Iterator { + public function next() {} + public function key() {} + public function rewind() {} + public function current() {} + public function valid() {} +} +Class IterarorAggregateImpl implements IteratorAggregate { + public function getIterator() {} +} +Class ExtendsIteratorImpl extends IteratorImpl { +} +Class ExtendsIteratorAggregateImpl extends IterarorAggregateImpl { +} +Class A { +} + +$classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate', + 'IteratorImpl', 'IterarorAggregateImpl', 'ExtendsIteratorImpl', 'ExtendsIteratorAggregateImpl', 'A'); + +foreach($classes as $class) { + $rc = new ReflectionClass($class); + echo "Is $class iterable? "; + var_dump($rc->isIterateable()); +} + +echo "\nTest invalid params:\n"; +$rc = new ReflectionClass('IteratorImpl'); +var_dump($rc->isIterateable(null)); +var_dump($rc->isIterateable(null, null)); +var_dump($rc->isIterateable(1)); +var_dump($rc->isIterateable(1.5)); +var_dump($rc->isIterateable(true)); +var_dump($rc->isIterateable('X')); +var_dump($rc->isIterateable(null)); + +echo "\nTest static invocation:\n"; +ReflectionClass::isIterateable(); + +?> +--EXPECTF-- +Is Traversable iterable? bool(false) +Is Iterator iterable? bool(false) +Is IteratorAggregate iterable? bool(false) +Is ExtendsIterator iterable? bool(false) +Is ExtendsIteratorAggregate iterable? bool(false) +Is IteratorImpl iterable? bool(true) +Is IterarorAggregateImpl iterable? bool(true) +Is ExtendsIteratorImpl iterable? bool(true) +Is ExtendsIteratorAggregateImpl iterable? bool(true) +Is A iterable? bool(false) + +Test invalid params: +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Test static invocation: + +Fatal error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s on line 43
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt b/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt new file mode 100644 index 000000000..083b27713 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt @@ -0,0 +1,49 @@ +--TEST-- +ReflectionObject::isSubclassOf() - bad arguments +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A {} +$rc = new ReflectionClass('A'); + +echo "\n\nTest bad arguments:\n"; +try { + var_dump($rc->isSubclassOf()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- + +Test bad arguments: + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 +NULL +Parameter one must either be a string or a ReflectionClass object +Class ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt new file mode 100644 index 000000000..941bfe5f2 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt @@ -0,0 +1,44 @@ +--TEST-- +Modifiers +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +abstract class A {} +class B extends A {} +class C {} +final class D {} +interface I {} + +$classes = array("A", "B", "C", "D", "I"); + +foreach ($classes as $class) { + $rc = new ReflectionClass($class); + var_dump($rc->isFinal()); + var_dump($rc->isInterface()); + var_dump($rc->isAbstract()); + var_dump($rc->getModifiers()); +} +?> +--EXPECTF-- +bool(false) +bool(false) +bool(true) +int(32) +bool(false) +bool(false) +bool(false) +int(0) +bool(false) +bool(false) +bool(false) +int(0) +bool(true) +bool(false) +bool(false) +int(64) +bool(false) +bool(true) +bool(false) +int(128)
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_modifiers_002.phpt b/ext/reflection/tests/ReflectionClass_modifiers_002.phpt new file mode 100644 index 000000000..3fa247454 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_modifiers_002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Modifiers - wrong param count +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C {} +$rc = new ReflectionClass("C"); +var_dump($rc->isFinal('X')); +var_dump($rc->isInterface(null)); +var_dump($rc->isAbstract(true)); +var_dump($rc->getModifiers(array(1,2,3))); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::isFinal() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInterface() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::isAbstract() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getModifiers() in %s on line 7 +NULL diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt new file mode 100644 index 000000000..981d67519 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::newInstanceArgs +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + public function A() { + echo "In constructor of class A\n"; + } +} + +class B { + public function __construct($a, $b) { + echo "In constructor of class B with args $a, $b\n"; + } +} + +class C { + protected function __construct() { + echo "In constructor of class C\n"; + } +} + +class D { + private function __construct() { + echo "In constructor of class D\n"; + } +} +class E { +} + + +$rcA = new ReflectionClass('A'); +$rcB = new ReflectionClass('B'); +$rcC = new ReflectionClass('C'); +$rcD = new ReflectionClass('D'); +$rcE = new ReflectionClass('E'); + +$a1 = $rcA->newInstanceArgs(); +$a2 = $rcA->newInstanceArgs(array('x')); +var_dump($a1, $a2); + +$b1 = $rcB->newInstanceArgs(); +$b2 = $rcB->newInstanceArgs(array('x', 123)); +var_dump($b1, $b2); + +try { + $rcC->newInstanceArgs(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + $rcD->newInstanceArgs(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +$e1 = $rcE->newInstanceArgs(); +var_dump($e1); + +try { + $e2 = $rcE->newInstanceArgs(array('x')); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +In constructor of class A +In constructor of class A +object(A)#%d (0) { +} +object(A)#%d (0) { +} + +Warning: Missing argument 1 for B::__construct() in %s on line 9 + +Warning: Missing argument 2 for B::__construct() in %s on line 9 + +Notice: Undefined variable: a in %s on line 10 + +Notice: Undefined variable: b in %s on line 10 +In constructor of class B with args , +In constructor of class B with args x, 123 +object(B)#%d (0) { +} +object(B)#%d (0) { +} +Access to non-public constructor of class C +Access to non-public constructor of class D +object(E)#%d (0) { +} +Class E does not have a constructor, so you cannot pass any constructor arguments
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt new file mode 100644 index 000000000..af5aeff2d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::newInstanceArgs() - wrong arg type +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + public function __construct($a, $b) { + echo "In constructor of class B with arg $a\n"; + } +} +$rc = new ReflectionClass('A'); +$a = $rc->newInstanceArgs('x'); +var_dump($a); + +?> +--EXPECTF-- + +Catchable fatal error: Argument 1 passed to ReflectionClass::newInstanceArgs() must be an array, string given in %s on line 8 diff --git a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt new file mode 100644 index 000000000..3cdb5d76b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::newInstance() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + public function A() { + echo "In constructor of class A\n"; + } +} + +class B { + public function __construct($a, $b) { + echo "In constructor of class B with args $a, $b\n"; + } +} + +class C { + protected function __construct() { + echo "In constructor of class C\n"; + } +} + +class D { + private function __construct() { + echo "In constructor of class D\n"; + } +} +class E { +} + + +$rcA = new ReflectionClass('A'); +$rcB = new ReflectionClass('B'); +$rcC = new ReflectionClass('C'); +$rcD = new ReflectionClass('D'); +$rcE = new ReflectionClass('E'); + +$a1 = $rcA->newInstance(); +$a2 = $rcA->newInstance('x'); +var_dump($a1, $a2); + +$b1 = $rcB->newInstance(); +$b2 = $rcB->newInstance('x', 123); +var_dump($b1, $b2); + +try { + $rcC->newInstance(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + $rcD->newInstance(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +$e1 = $rcE->newInstance(); +var_dump($e1); + +try { + $e2 = $rcE->newInstance('x'); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +In constructor of class A +In constructor of class A +object(A)#%d (0) { +} +object(A)#%d (0) { +} + +Warning: Missing argument 1 for B::__construct() in %s on line 9 + +Warning: Missing argument 2 for B::__construct() in %s on line 9 + +Notice: Undefined variable: a in %s on line 10 + +Notice: Undefined variable: b in %s on line 10 +In constructor of class B with args , +In constructor of class B with args x, 123 +object(B)#%d (0) { +} +object(B)#%d (0) { +} +Access to non-public constructor of class C +Access to non-public constructor of class D +object(E)#%d (0) { +} +Class E does not have a constructor, so you cannot pass any constructor arguments
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt new file mode 100644 index 000000000..70a3bab9c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt @@ -0,0 +1,77 @@ +--TEST-- +ReflectionClass::setStaticPropertyValue() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class A { + static private $privateOverridden = "original private"; + static protected $protectedOverridden = "original protected"; + static public $publicOverridden = "original public"; +} + +class B extends A { + static private $privateOverridden = "changed private"; + static protected $protectedOverridden = "changed protected"; + static public $publicOverridden = "changed public"; +} + +echo "Set static values in A:\n"; +$rcA = new ReflectionClass('A'); +$rcA->setStaticPropertyValue("\0A\0privateOverridden", "new value 1"); +$rcA->setStaticPropertyValue("\0*\0protectedOverridden", "new value 2"); +$rcA->setStaticPropertyValue("publicOverridden", "new value 3"); +print_r($rcA->getStaticProperties()); + +echo "\nSet static values in B:\n"; +$rcB = new ReflectionClass('B'); +$rcB->setStaticPropertyValue("\0A\0privateOverridden", "new value 4"); +$rcB->setStaticPropertyValue("\0B\0privateOverridden", "new value 5"); +$rcB->setStaticPropertyValue("\0*\0protectedOverridden", "new value 6"); +$rcB->setStaticPropertyValue("publicOverridden", "new value 7"); +print_r($rcA->getStaticProperties()); +print_r($rcB->getStaticProperties()); + +echo "\nSet non-existent values from A with no default value:\n"; +try { + var_dump($rcA->setStaticPropertyValue("protectedOverridden", "new value 8")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump($rcA->setStaticPropertyValue("privateOverridden", "new value 9")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +Set static values in A: +Array +( + [privateOverridden] => new value 1 + [protectedOverridden] => new value 2 + [publicOverridden] => new value 3 +) + +Set static values in B: +Array +( + [privateOverridden] => new value 4 + [protectedOverridden] => new value 2 + [publicOverridden] => new value 3 +) +Array +( + [privateOverridden] => new value 4 + [protectedOverridden] => new value 6 + [publicOverridden] => new value 7 +) + +Set non-existent values from A with no default value: +Class A does not have a property named protectedOverridden +Class A does not have a property named privateOverridden
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt new file mode 100644 index 000000000..3244ec30b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt @@ -0,0 +1,60 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() - bad params +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C { + public static $x; +} + +$rc = new ReflectionClass('C'); +try { + var_dump($rc->setStaticPropertyValue("x", "default value", 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(null,null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(1.5, 'def')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(array(1,2,3), 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 3 given in %s on line 8 +NULL + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 0 given in %s on line 13 +NULL + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 1 given in %s on line 18 +NULL +Class C does not have a property named +Class C does not have a property named 1.5 + +Warning: ReflectionClass::setStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 33 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt new file mode 100644 index 000000000..8f567f478 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -0,0 +1,224 @@ +--TEST-- +ReflectionClass::__toString() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +$rc = new ReflectionClass("ReflectionClass"); +echo $rc; +?> +--EXPECTF-- +Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { + + - Constants [3] { + Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } + Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } + Constant [ integer IS_FINAL ] { 64 } + } + + - Static properties [0] { + } + + - Static methods [1] { + Method [ <internal:Reflection> static public method export ] { + + - Parameters [2] { + Parameter #0 [ <required> $argument ] + Parameter #1 [ <optional> $return ] + } + } + } + + - Properties [1] { + Property [ <default> public $name ] + } + + - Methods [40] { + Method [ <internal:Reflection> final private method __clone ] { + } + + Method [ <internal:Reflection, ctor> public method __construct ] { + + - Parameters [1] { + Parameter #0 [ <required> $argument ] + } + } + + Method [ <internal:Reflection> public method __toString ] { + } + + Method [ <internal:Reflection> public method getName ] { + } + + Method [ <internal:Reflection> public method isInternal ] { + } + + Method [ <internal:Reflection> public method isUserDefined ] { + } + + Method [ <internal:Reflection> public method isInstantiable ] { + } + + Method [ <internal:Reflection> public method getFileName ] { + } + + Method [ <internal:Reflection> public method getStartLine ] { + } + + Method [ <internal:Reflection> public method getEndLine ] { + } + + Method [ <internal:Reflection> public method getDocComment ] { + } + + Method [ <internal:Reflection> public method getConstructor ] { + } + + Method [ <internal:Reflection> public method hasMethod ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getMethod ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getMethods ] { + + - Parameters [1] { + Parameter #0 [ <optional> $filter ] + } + } + + Method [ <internal:Reflection> public method hasProperty ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getProperty ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getProperties ] { + + - Parameters [1] { + Parameter #0 [ <optional> $filter ] + } + } + + Method [ <internal:Reflection> public method hasConstant ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getConstants ] { + } + + Method [ <internal:Reflection> public method getConstant ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + + Method [ <internal:Reflection> public method getInterfaces ] { + } + + Method [ <internal:Reflection> public method getInterfaceNames ] { + } + + Method [ <internal:Reflection> public method isInterface ] { + } + + Method [ <internal:Reflection> public method isAbstract ] { + } + + Method [ <internal:Reflection> public method isFinal ] { + } + + Method [ <internal:Reflection> public method getModifiers ] { + } + + Method [ <internal:Reflection> public method isInstance ] { + + - Parameters [1] { + Parameter #0 [ <required> $object ] + } + } + + Method [ <internal:Reflection> public method newInstance ] { + + - Parameters [1] { + Parameter #0 [ <required> $args ] + } + } + + Method [ <internal:Reflection> public method newInstanceArgs ] { + + - Parameters [1] { + Parameter #0 [ <optional> array $args ] + } + } + + Method [ <internal:Reflection> public method getParentClass ] { + } + + Method [ <internal:Reflection> public method isSubclassOf ] { + + - Parameters [1] { + Parameter #0 [ <required> $class ] + } + } + + Method [ <internal:Reflection> public method getStaticProperties ] { + } + + Method [ <internal:Reflection> public method getStaticPropertyValue ] { + + - Parameters [2] { + Parameter #0 [ <required> $name ] + Parameter #1 [ <optional> $default ] + } + } + + Method [ <internal:Reflection> public method setStaticPropertyValue ] { + + - Parameters [2] { + Parameter #0 [ <required> $name ] + Parameter #1 [ <required> $value ] + } + } + + Method [ <internal:Reflection> public method getDefaultProperties ] { + } + + Method [ <internal:Reflection> public method isIterateable ] { + } + + Method [ <internal:Reflection> public method implementsInterface ] { + + - Parameters [1] { + Parameter #0 [ <required> $interface ] + } + } + + Method [ <internal:Reflection> public method getExtension ] { + } + + Method [ <internal:Reflection> public method getExtensionName ] { + } + } +} diff --git a/ext/reflection/tests/ReflectionClass_toString_002.phpt b/ext/reflection/tests/ReflectionClass_toString_002.phpt new file mode 100644 index 000000000..e9aaa502c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_002.phpt @@ -0,0 +1,123 @@ +--TEST-- +ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +Class A { + function f() {} +} +Class B extends A { + function f() {} +} +Class C extends B { + +} +Class D extends C { + function f() {} +} +foreach (array('A', 'B', 'C', 'D') as $class) { + echo "\n\n----( Reflection class $class: )----\n"; + $rc = new ReflectionClass($class); + echo $rc; +} + +?> +--EXPECTF-- + + +----( Reflection class A: )---- +Class [ <user> class A ] { + @@ %s 2-4 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user> public method f ] { + @@ %s 3 - 3 + } + } +} + + +----( Reflection class B: )---- +Class [ <user> class B extends A ] { + @@ %s 5-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, overwrites A, prototype A> public method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class C: )---- +Class [ <user> class C extends B ] { + @@ %s 8-10 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, inherits B, prototype A> public method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class D: )---- +Class [ <user> class D extends C ] { + @@ %s 11-13 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, overwrites B, prototype A> public method f ] { + @@ %s 12 - 12 + } + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_toString_003.phpt b/ext/reflection/tests/ReflectionClass_toString_003.phpt new file mode 100644 index 000000000..cf926395a --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_003.phpt @@ -0,0 +1,123 @@ +--TEST-- +ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation with private methods +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +Class A { + private function f() {} +} +Class B extends A { + private function f() {} +} +Class C extends B { + +} +Class D extends C { + private function f() {} +} +foreach (array('A', 'B', 'C', 'D') as $class) { + echo "\n\n----( Reflection class $class: )----\n"; + $rc = new ReflectionClass($class); + echo $rc; +} + +?> +--EXPECTF-- + + +----( Reflection class A: )---- +Class [ <user> class A ] { + @@ %s 2-4 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user> private method f ] { + @@ %s 3 - 3 + } + } +} + + +----( Reflection class B: )---- +Class [ <user> class B extends A ] { + @@ %s 5-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, overwrites A> private method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class C: )---- +Class [ <user> class C extends B ] { + @@ %s 8-10 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, inherits B> private method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class D: )---- +Class [ <user> class D extends C ] { + @@ %s 11-13 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, overwrites B> private method f ] { + @@ %s 12 - 12 + } + } +} diff --git a/ext/reflection/tests/ReflectionFunction_001.phpt b/ext/reflection/tests/ReflectionFunction_001.phpt new file mode 100644 index 000000000..7c592dc61 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_001.phpt @@ -0,0 +1,67 @@ +--TEST-- +ReflectionFunction methods +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +/** + * my doc comment + */ +function foo () { + static $c; + static $a = 1; + static $b = "hello"; + $d = 5; +} + +/*** + * not a doc comment + */ +function bar () {} + + +function dumpFuncInfo($name) { + $funcInfo = new ReflectionFunction($name); + var_dump($funcInfo->getName()); + var_dump($funcInfo->isInternal()); + var_dump($funcInfo->isUserDefined()); + var_dump($funcInfo->getStartLine()); + var_dump($funcInfo->getEndLine()); + var_dump($funcInfo->getStaticVariables()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECT-- +string(3) "foo" +bool(false) +bool(true) +int(6) +int(11) +array(3) { + ["c"]=> + NULL + ["a"]=> + int(1) + ["b"]=> + string(5) "hello" +} +string(3) "bar" +bool(false) +bool(true) +int(16) +int(16) +array(0) { +} +string(7) "extract" +bool(true) +bool(false) +bool(false) +bool(false) +array(0) { +}
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt new file mode 100644 index 000000000..c8e0a17a9 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionFunction constructor errors +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +$a = new ReflectionFunction(array(1, 2, 3)); +try { + $a = new ReflectionFunction('nonExistentFunction'); +} catch (Exception $e) { + echo $e->getMessage(); +} +$a = new ReflectionFunction(); +$a = new ReflectionFunction(1, 2); +?> +--EXPECTF-- +Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d +Function nonExistentFunction() does not exist +Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d diff --git a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt new file mode 100644 index 000000000..38c278d8a --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionFunction::getDocComment() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +/** + * my doc comment + */ +function foo () { + static $c; + static $a = 1; + static $b = "hello"; + $d = 5; +} + +/*** + * not a doc comment + */ +function bar () {} + + +function dumpFuncInfo($name) { + $funcInfo = new ReflectionFunction($name); + var_dump($funcInfo->getDocComment()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECTF-- +string(%d) "/** + * my doc comment + */" +bool(false) +bool(false) + diff --git a/ext/reflection/tests/ReflectionFunction_getExtension.phpt b/ext/reflection/tests/ReflectionFunction_getExtension.phpt new file mode 100644 index 000000000..18345892c --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getExtension.phpt @@ -0,0 +1,19 @@ +--TEST-- +ReflectionFunction::getExtension() +--FILE-- +<?php +function foo () {} + +$function = new ReflectionFunction('sort'); +var_dump($function->getExtension()); + +$function = new ReflectionFunction('foo'); +var_dump($function->getExtension()); +?> +--EXPECTF-- +object(ReflectionExtension)#%i (1) { + ["name"]=> + string(8) "standard" +} +NULL + diff --git a/ext/reflection/tests/ReflectionFunction_getExtensionName.phpt b/ext/reflection/tests/ReflectionFunction_getExtensionName.phpt new file mode 100644 index 000000000..7553a50b3 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getExtensionName.phpt @@ -0,0 +1,16 @@ +--TEST-- +ReflectionFunction::getExtensionName() +--FILE-- +<?php +function foo() {} + +$function = new ReflectionFunction('sort'); +var_dump($function->getExtensionName()); + +$function = new ReflectionFunction('foo'); +var_dump($function->getExtensionName()); +?> +--EXPECT-- +string(8) "standard" +bool(false) + diff --git a/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt b/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt new file mode 100644 index 000000000..5dbe7b54b --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt @@ -0,0 +1,18 @@ +--TEST-- +ReflectionFunction::getFileName() with function in an included file +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +include "included4.inc"; + +$funcInfo = new ReflectionFunction('g'); +var_dump($funcInfo->getFileName()); + +?> +--EXPECTF-- +%sincluded4.inc +%d +string(%d) "%sincluded4.inc"
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt b/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt new file mode 100644 index 000000000..455935e38 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionFunction::getFileName() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +/** + * my doc comment + */ +function foo () { + static $c; + static $a = 1; + static $b = "hello"; + $d = 5; +} + +/*** + * not a doc comment + */ +function bar () {} + + +function dumpFuncInfo($name) { + $funcInfo = new ReflectionFunction($name); + var_dump($funcInfo->getFileName()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECTF-- +string(%d) "%sReflectionFunction_getFileName.002.php" +string(%d) "%sReflectionFunction_getFileName.002.php" +bool(false) + diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt new file mode 100644 index 000000000..4a8192b9e --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_006.phpt @@ -0,0 +1,100 @@ +--TEST-- +ReflectionMethod methods - wrong num args +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +var_dump(new ReflectionMethod()); +var_dump(new ReflectionMethod('a', 'b', 'c')); + +class C { + public function f() {} +} + +$rm = new ReflectionMethod('C', 'f'); + +var_dump($rm->isFinal(1)); +var_dump($rm->isAbstract(1)); +var_dump($rm->isPrivate(1)); +var_dump($rm->isProtected(1)); +var_dump($rm->isPublic(1)); +var_dump($rm->isStatic(1)); +var_dump($rm->isConstructor(1)); +var_dump($rm->isDestructor(1)); +var_dump($rm->getModifiers(1)); +var_dump($rm->isInternal(1)); +var_dump($rm->isUserDefined(1)); +var_dump($rm->getFileName(1)); +var_dump($rm->getStartLine(1)); +var_dump($rm->getEndLine(1)); +var_dump($rm->getStaticVariables(1)); +var_dump($rm->getName(1)); + + +?> +--EXPECTF-- +Warning: ReflectionMethod::__construct() expects %s on line 3 +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: ReflectionMethod::__construct() expects %s on line 4 +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: Wrong parameter count for ReflectionMethod::isFinal() in %s on line 12 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isAbstract() in %s on line 13 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isPrivate() in %s on line 14 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isProtected() in %s on line 15 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isPublic() in %s on line 16 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isStatic() in %s on line 17 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isConstructor() in %s on line 18 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isDestructor() in %s on line 19 +NULL + +Warning: Wrong parameter count for ReflectionMethod::getModifiers() in %s on line 20 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::isInternal() in %s on line 21 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::isUserDefined() in %s on line 22 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getFileName() in %s on line 23 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getStartLine() in %s on line 24 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getEndLine() in %s on line 25 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getStaticVariables() in %s on line 26 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getName() in %s on line 27 +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt new file mode 100644 index 000000000..70528255e --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt @@ -0,0 +1,103 @@ +--TEST-- +ReflectionMethod constructor errors +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +class TestClass +{ + public function foo() { + } +} + + +try { + echo "\nWrong type of argument (bool):\n"; + $methodInfo = new ReflectionMethod(true); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nWrong type of argument (int):\n"; + $methodInfo = new ReflectionMethod(3); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nWrong type of argument (bool, string):\n"; + $methodInfo = new ReflectionMethod(true, "foo"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nWrong type of argument (string, bool):\n"; + $methodInfo = new ReflectionMethod('TestClass', true); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nNo method given:\n"; + $methodInfo = new ReflectionMethod("TestClass"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string, bad method name:\n"; + $methodInfo = new ReflectionMethod("TestClass::foop::dedoop"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string, bad class name:\n"; + $methodInfo = new ReflectionMethod("TestCla::foo"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string (ok):\n"; + $methodInfo = new ReflectionMethod("TestClass::foo"); +} catch (Exception $e) { + print $e->__toString(); +} + +?> +--EXPECTF-- +Wrong type of argument (bool): +exception 'ReflectionException' with message 'Invalid method name 1' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('1') +#1 {main} +Wrong type of argument (int): +exception 'ReflectionException' with message 'Invalid method name 3' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('3') +#1 {main} +Wrong type of argument (bool, string): +exception 'ReflectionException' with message 'The parameter class is expected to be either a string or an object' in %s +Stack trace: +#0 %s ReflectionMethod->__construct(true, 'foo') +#1 {main} +Wrong type of argument (string, bool): +exception 'ReflectionException' with message 'Method TestClass::1() does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass', '1') +#1 {main} +No method given: +exception 'ReflectionException' with message 'Invalid method name TestClass' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass') +#1 {main} +Class and Method in same string, bad method name: +exception 'ReflectionException' with message 'Method TestClass::foop::dedoop() does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass::foop...') +#1 {main} +Class and Method in same string, bad class name: +exception 'ReflectionException' with message 'Class TestCla does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestCla::foo') +#1 {main} +Class and Method in same string (ok): + diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt new file mode 100644 index 000000000..1c2d3a138 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionMethod constructor errors +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +class TestClass +{ + public function foo() { + } +} + + +try { + echo "Too few arguments:\n"; + $methodInfo = new ReflectionMethod(); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nToo many arguments:\n"; + $methodInfo = new ReflectionMethod("TestClass", "foo", true); +} catch (Exception $e) { + print $e->__toString(); +} + +?> +--EXPECTF-- +Too few arguments: + +Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 + +Too many arguments: + +Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 diff --git a/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt b/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt new file mode 100644 index 000000000..2fb8cb087 --- /dev/null +++ b/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt @@ -0,0 +1,48 @@ +--TEST-- +ReflectionObject::isSubclassOf() - bad arguments +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class C {} +$ro = new ReflectionObject(new C); + +echo "\n\nTest bad arguments:\n"; +try { + var_dump($ro->isSubclassOf()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Test bad arguments: + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 +NULL +Parameter one must either be a string or a ReflectionClass object +Class ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_001.phpt b/ext/reflection/tests/ReflectionParameter_001.phpt new file mode 100644 index 000000000..dae3ac723 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_001.phpt @@ -0,0 +1,80 @@ +--TEST-- +ReflectionParameter class - getNames() method. +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class ReflectTestClass { + public static function twoArgFunction($theIncrement, $anotherParam) { + return ++$theIncrement; + } + + public function oneArgNonStatic($theParam) { + $theParam--; + } + + public function noArgs() { + echo "No arg function\n"; + } +} + +// Create an instance of the Reflection_Method class +$method = new ReflectionMethod('ReflectTestClass', 'twoArgFunction'); +// Get the parameters +$parameters = $method->getParameters(); +echo "Parameters from twoArgMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + +$method = new ReflectionMethod('ReflectTestClass', 'oneArgNonStatic'); +$parameters = $method->getParameters(); +echo "Parameters from oneArgNonStatic:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + + +$method = new ReflectionMethod('ReflectTestClass', 'noArgs'); +$parameters = $method->getParameters(); +echo "Parameters from noArgs:\n\n"; +var_dump($parameters); +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + +echo "done\n"; + +?> +--EXPECTF-- +Parameters from twoArgMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "theIncrement" +} + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "anotherParam" +} + +Parameters from oneArgNonStatic: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(8) "theParam" +} + +Parameters from noArgs: + +array(0) { +} +done
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_002.phpt b/ext/reflection/tests/ReflectionParameter_002.phpt new file mode 100644 index 000000000..3b7df6f95 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_002.phpt @@ -0,0 +1,80 @@ +--TEST-- +ReflectionParameter class - isPassedByReferenceMethod() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php +class ReflectTestClass { + public static function staticMethod(&$paramOne, $anotherParam) { + return ++$theIncrement; + } + + public function instanceMethod($firstParam, &$secondParam) { + $firstParam = "Hello\n"; + } +} + +// Create an instance of the Reflection_Method class +$method = new ReflectionMethod('ReflectTestClass', 'staticMethod'); +// Get the parameters +$parameters = $method->getParameters(); +echo "Parameters from staticMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + if($parameter->isPassedByReference()) { + echo "This param is passed by reference\n"; + } else { + echo "This param is not passed by reference\n"; + } + echo "\n"; +} + +// Create an instance of the Reflection_Method class +$method = new ReflectionMethod('ReflectTestClass', 'instanceMethod'); +// Get the parameters +$parameters = $method->getParameters(); +echo "Parameters from instanceMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + if($parameter->isPassedByReference()) { + echo "This param is passed by reference\n"; + } else { + echo "This param is not passed by reference\n"; + } + echo "\n"; +} + +echo "done\n"; + +?> +--EXPECTF-- +Parameters from staticMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(8) "paramOne" +} +This param is passed by reference + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "anotherParam" +} +This param is not passed by reference + +Parameters from instanceMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(10) "firstParam" +} +This param is not passed by reference + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(11) "secondParam" +} +This param is passed by reference + +done
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_003.phpt b/ext/reflection/tests/ReflectionParameter_003.phpt new file mode 100644 index 000000000..f7ced9ad0 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_003.phpt @@ -0,0 +1,88 @@ +--TEST-- +ReflectionParameter class - isOptional, isDefaultValueAvailable and getDefaultValue methods. +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +class ReflectTestClass { + public static function staticMethod($paramOne, $anotherParam = "bob", + &$thirdParam = "jack", $arrayParam = array('one')) { + echo "hello from test\n"; + echo "third is $thirdParam\n"; + return ++$theIncrement; + } + +} + +$jane = "jane"; +ReflectTestClass::staticMethod("bob", "jack"); + +$refMethod = new ReflectionMethod('ReflectTestClass', 'staticMethod'); +$refParameters = $refMethod->getParameters(); + +echo "parameter names from staticMethod method:\n\n"; +foreach($refParameters as $parameter) { + var_dump($parameter); + if($parameter->isOptional()) { + echo "this parameter is optional\n"; + } else { + echo "this parameter is not optional\n"; + } + + if($parameter->isDefaultValueAvailable()) { + echo "this parameter has a default value\n"; + } else { + echo "this parameter has no default value\n"; + } + + /* + $val = 0; + try { + $val = $parameter->getDefaultValue(); + var_dump($val); + } catch (ReflectionException $e) { + print $e->getMessage(); + echo "\n"; + } + */ + + echo "\n"; +} + +?> +--EXPECTF-- +hello from test +third is jack + +Notice: Undefined variable: theIncrement in %s on line 8 +parameter names from staticMethod method: + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(8) "paramOne" +} +this parameter is not optional +this parameter has no default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(12) "anotherParam" +} +this parameter is optional +this parameter has a default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(10) "thirdParam" +} +this parameter is optional +this parameter has a default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(10) "arrayParam" +} +this parameter is optional +this parameter has a default value diff --git a/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt new file mode 100644 index 000000000..fe888a83b --- /dev/null +++ b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt @@ -0,0 +1,66 @@ +--TEST-- +ReflectionProperty::getModifiers() +--CREDITS-- +Robin Fernandes <robinf@php.net> +Steve Seear <stevseea@php.net> +--FILE-- +<?php + +function reflectProperty($class, $property) { + $propInfo = new ReflectionProperty($class, $property); + + echo "**********************************\n"; + echo "Reflecting on property $class::$property\n\n"; + + echo "getModifiers():\n"; + var_dump($propInfo->getModifiers()); + + echo "\n**********************************\n"; +} + +class TestClass +{ + public $pub; + static public $stat = "static property"; + /** + * This property has a comment. + */ + protected $prot = 4; + private $priv = "keepOut"; +} + +reflectProperty("TestClass", "pub"); +reflectProperty("TestClass", "stat"); +reflectProperty("TestClass", "prot"); +reflectProperty("TestClass", "priv"); + +?> +--EXPECT-- +********************************** +Reflecting on property TestClass::pub + +getModifiers(): +int(256) + +********************************** +********************************** +Reflecting on property TestClass::stat + +getModifiers(): +int(257) + +********************************** +********************************** +Reflecting on property TestClass::prot + +getModifiers(): +int(512) + +********************************** +********************************** +Reflecting on property TestClass::priv + +getModifiers(): +int(1024) + +********************************** diff --git a/ext/reflection/tests/bug26695.phpt b/ext/reflection/tests/bug26695.phpt index c62395325..22619d4f1 100755 --- a/ext/reflection/tests/bug26695.phpt +++ b/ext/reflection/tests/bug26695.phpt @@ -1,27 +1,27 @@ ---TEST--
-Reflection Bug #26695 (Reflection API does not recognize mixed-case class hints)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class Foo {
-}
-
-class Bar {
- function demo(foo $f) {
- }
-}
-
-$class = new ReflectionClass('bar');
-$methods = $class->getMethods();
-$params = $methods[0]->getParameters();
-
-$class = $params[0]->getClass();
-
-var_dump($class->getName());
-?>
-===DONE===
---EXPECT--
-string(3) "Foo"
+--TEST-- +Reflection Bug #26695 (Reflection API does not recognize mixed-case class hints) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class Foo { +} + +class Bar { + function demo(foo $f) { + } +} + +$class = new ReflectionClass('bar'); +$methods = $class->getMethods(); +$params = $methods[0]->getParameters(); + +$class = $params[0]->getClass(); + +var_dump($class->getName()); +?> +===DONE=== +--EXPECT-- +string(3) "Foo" ===DONE===
\ No newline at end of file diff --git a/ext/reflection/tests/bug29268.phpt b/ext/reflection/tests/bug29268.phpt index 9f17a5e11..cd8f9b8ed 100755 --- a/ext/reflection/tests/bug29268.phpt +++ b/ext/reflection/tests/bug29268.phpt @@ -1,29 +1,29 @@ ---TEST--
-Reflection Bug #29268 (__autoload() not called with reflectionProperty->getClass())
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-function __autoload($classname) {
- echo "__autoload($classname)\n";
- eval("class $classname {}");
-}
-
-class B{
- public function doit(A $a){
- }
-}
-
-$ref = new reflectionMethod('B','doit');
-$parameters = $ref->getParameters();
-foreach($parameters as $parameter)
-{
- $class = $parameter->getClass();
- echo $class->name."\n";
-}
-echo "ok\n";
-?>
---EXPECT--
-__autoload(A)
-A
-ok
+--TEST-- +Reflection Bug #29268 (__autoload() not called with reflectionProperty->getClass()) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +function __autoload($classname) { + echo "__autoload($classname)\n"; + eval("class $classname {}"); +} + +class B{ + public function doit(A $a){ + } +} + +$ref = new reflectionMethod('B','doit'); +$parameters = $ref->getParameters(); +foreach($parameters as $parameter) +{ + $class = $parameter->getClass(); + echo $class->name."\n"; +} +echo "ok\n"; +?> +--EXPECT-- +__autoload(A) +A +ok diff --git a/ext/reflection/tests/bug29523.phpt b/ext/reflection/tests/bug29523.phpt index e952d0ffe..ac83cc789 100755 --- a/ext/reflection/tests/bug29523.phpt +++ b/ext/reflection/tests/bug29523.phpt @@ -1,40 +1,40 @@ ---TEST--
-Reflection Bug #29523 (ReflectionParameter::isOptional() is incorrect)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class TestClass
-{
-}
-
-function optionalTest(TestClass $a, TestClass $b, $c = 3)
-{
-}
-
-$function = new ReflectionFunction('optionalTest');
-$numberOfNotOptionalParameters = 0;
-$numberOfOptionalParameters = 0;
-foreach($function->getParameters() as $parameter)
-{
- var_dump($parameter->isOptional());
- if ($parameter->isOptional())
- {
- ++$numberOfOptionalParameters;
- }
- else
- {
- ++$numberOfNotOptionalParameters;
- }
-}
-var_dump($function->getNumberOfRequiredParameters());
-var_dump($numberOfNotOptionalParameters);
-
-?>
---EXPECT--
-bool(false)
-bool(false)
-bool(true)
-int(2)
-int(2)
+--TEST-- +Reflection Bug #29523 (ReflectionParameter::isOptional() is incorrect) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass +{ +} + +function optionalTest(TestClass $a, TestClass $b, $c = 3) +{ +} + +$function = new ReflectionFunction('optionalTest'); +$numberOfNotOptionalParameters = 0; +$numberOfOptionalParameters = 0; +foreach($function->getParameters() as $parameter) +{ + var_dump($parameter->isOptional()); + if ($parameter->isOptional()) + { + ++$numberOfOptionalParameters; + } + else + { + ++$numberOfNotOptionalParameters; + } +} +var_dump($function->getNumberOfRequiredParameters()); +var_dump($numberOfNotOptionalParameters); + +?> +--EXPECT-- +bool(false) +bool(false) +bool(true) +int(2) +int(2) diff --git a/ext/reflection/tests/bug29828.phpt b/ext/reflection/tests/bug29828.phpt index f9052ac6b..7d4de40c1 100755 --- a/ext/reflection/tests/bug29828.phpt +++ b/ext/reflection/tests/bug29828.phpt @@ -1,37 +1,37 @@ ---TEST--
-Reflection Bug #29828 (Interfaces no longer work)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-interface Bla
-{
- function bla();
-}
-
-class BlaMore implements Bla
-{
- function bla()
- {
- echo "Hello\n";
- }
-}
-
-$r = new ReflectionClass('BlaMore');
-
-var_dump(count($r->getMethods()));
-var_dump($r->getMethod('bla')->isConstructor());
-var_dump($r->getMethod('bla')->isAbstract());
-
-$o=new BlaMore;
-$o->bla();
-
-?>
-===DONE===
---EXPECT--
-int(1)
-bool(false)
-bool(false)
-Hello
-===DONE===
+--TEST-- +Reflection Bug #29828 (Interfaces no longer work) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +interface Bla +{ + function bla(); +} + +class BlaMore implements Bla +{ + function bla() + { + echo "Hello\n"; + } +} + +$r = new ReflectionClass('BlaMore'); + +var_dump(count($r->getMethods())); +var_dump($r->getMethod('bla')->isConstructor()); +var_dump($r->getMethod('bla')->isAbstract()); + +$o=new BlaMore; +$o->bla(); + +?> +===DONE=== +--EXPECT-- +int(1) +bool(false) +bool(false) +Hello +===DONE=== diff --git a/ext/reflection/tests/bug30146.phpt b/ext/reflection/tests/bug30146.phpt index d7dd2fc21..3a7ce92a0 100755 --- a/ext/reflection/tests/bug30146.phpt +++ b/ext/reflection/tests/bug30146.phpt @@ -1,25 +1,25 @@ ---TEST--
-Reflection Bug #30146 (ReflectionProperty->getValue() requires instance for static property)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-class test {
- static public $a = 1;
-}
-
-$r = new ReflectionProperty('test', 'a');
-var_dump($r->getValue(null));
-
-$r->setValue(NULL, 2);
-var_dump($r->getValue());
-
-$r->setValue(3);
-var_dump($r->getValue());
-?>
-===DONE===
---EXPECT--
-int(1)
-int(2)
-int(3)
+--TEST-- +Reflection Bug #30146 (ReflectionProperty->getValue() requires instance for static property) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class test { + static public $a = 1; +} + +$r = new ReflectionProperty('test', 'a'); +var_dump($r->getValue(null)); + +$r->setValue(NULL, 2); +var_dump($r->getValue()); + +$r->setValue(3); +var_dump($r->getValue()); +?> +===DONE=== +--EXPECT-- +int(1) +int(2) +int(3) ===DONE===
\ No newline at end of file diff --git a/ext/reflection/tests/bug30148.phpt b/ext/reflection/tests/bug30148.phpt index 91bc31b65..d058aaa24 100755 --- a/ext/reflection/tests/bug30148.phpt +++ b/ext/reflection/tests/bug30148.phpt @@ -1,37 +1,37 @@ ---TEST--
-Reflection Bug #30148 (ReflectionMethod->isConstructor() fails for inherited classes)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class Root
-{
- function Root() {}
-}
-class Base extends Root
-{
- function __construct() {}
-}
-class Derived extends Base
-{
-}
-$a = new ReflectionMethod('Root','Root');
-$b = new ReflectionMethod('Base','Root');
-$c = new ReflectionMethod('Base','__construct');
-$d = new ReflectionMethod('Derived','Root');
-$e = new ReflectionMethod('Derived','__construct');
-var_dump($a->isConstructor());
-var_dump($b->isConstructor());
-var_dump($c->isConstructor());
-var_dump($d->isConstructor());
-var_dump($e->isConstructor());
-?>
-===DONE===
---EXPECT--
-bool(true)
-bool(false)
-bool(true)
-bool(false)
-bool(true)
+--TEST-- +Reflection Bug #30148 (ReflectionMethod->isConstructor() fails for inherited classes) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class Root +{ + function Root() {} +} +class Base extends Root +{ + function __construct() {} +} +class Derived extends Base +{ +} +$a = new ReflectionMethod('Root','Root'); +$b = new ReflectionMethod('Base','Root'); +$c = new ReflectionMethod('Base','__construct'); +$d = new ReflectionMethod('Derived','Root'); +$e = new ReflectionMethod('Derived','__construct'); +var_dump($a->isConstructor()); +var_dump($b->isConstructor()); +var_dump($c->isConstructor()); +var_dump($d->isConstructor()); +var_dump($e->isConstructor()); +?> +===DONE=== +--EXPECT-- +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) ===DONE===
\ No newline at end of file diff --git a/ext/reflection/tests/bug30856.phpt b/ext/reflection/tests/bug30856.phpt index eaa6cf289..e5f06ab05 100755 --- a/ext/reflection/tests/bug30856.phpt +++ b/ext/reflection/tests/bug30856.phpt @@ -1,22 +1,22 @@ ---TEST--
-Reflection Bug #30856 (ReflectionClass::getStaticProperties segfaults)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-class bogus {
- const C = 'test';
- static $a = bogus::C;
-}
-
-$class = new ReflectionClass('bogus');
-
-var_dump($class->getStaticProperties());
-?>
-===DONE===
---EXPECT--
-array(1) {
- ["a"]=>
- string(4) "test"
-}
-===DONE===
+--TEST-- +Reflection Bug #30856 (ReflectionClass::getStaticProperties segfaults) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class bogus { + const C = 'test'; + static $a = bogus::C; +} + +$class = new ReflectionClass('bogus'); + +var_dump($class->getStaticProperties()); +?> +===DONE=== +--EXPECT-- +array(1) { + ["a"]=> + string(4) "test" +} +===DONE=== diff --git a/ext/reflection/tests/bug30961.phpt b/ext/reflection/tests/bug30961.phpt index c765e7cc8..dab07417b 100755 --- a/ext/reflection/tests/bug30961.phpt +++ b/ext/reflection/tests/bug30961.phpt @@ -1,22 +1,22 @@ ---TEST--
-Reflection Bug #30961 (Wrong linenumber in ReflectionClass getStartLine())
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
- class a
- {
- }
-
- class b extends a
- {
- }
-
- $ref1 = new ReflectionClass('a');
- $ref2 = new ReflectionClass('b');
- echo $ref1->getStartLine() . "\n";
- echo $ref2->getStartLine() . "\n";
-?>
---EXPECT--
-2
-6
+--TEST-- +Reflection Bug #30961 (Wrong linenumber in ReflectionClass getStartLine()) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + class a + { + } + + class b extends a + { + } + + $ref1 = new ReflectionClass('a'); + $ref2 = new ReflectionClass('b'); + echo $ref1->getStartLine() . "\n"; + echo $ref2->getStartLine() . "\n"; +?> +--EXPECT-- +2 +6 diff --git a/ext/reflection/tests/bug33312.phpt b/ext/reflection/tests/bug33312.phpt index 2413a3dc3..b39ec3c6f 100755 --- a/ext/reflection/tests/bug33312.phpt +++ b/ext/reflection/tests/bug33312.phpt @@ -1,22 +1,22 @@ ---TEST--
-Reflection Bug #33312 (ReflectionParameter methods do not work correctly)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-class Foo {
- public function bar(Foo $foo, $bar = 'bar') {
- }
-}
-
-$class = new ReflectionClass('Foo');
-$method = $class->getMethod('bar');
-
-foreach ($method->getParameters() as $parameter) {
- if ($parameter->isDefaultValueAvailable()) {
- print $parameter->getDefaultValue()."\n";
- }
-}
-?>
---EXPECT--
-bar
+--TEST-- +Reflection Bug #33312 (ReflectionParameter methods do not work correctly) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class Foo { + public function bar(Foo $foo, $bar = 'bar') { + } +} + +$class = new ReflectionClass('Foo'); +$method = $class->getMethod('bar'); + +foreach ($method->getParameters() as $parameter) { + if ($parameter->isDefaultValueAvailable()) { + print $parameter->getDefaultValue()."\n"; + } +} +?> +--EXPECT-- +bar diff --git a/ext/reflection/tests/bug38942.phpt b/ext/reflection/tests/bug38942.phpt index a1ba05ba0..a02f596af 100755 --- a/ext/reflection/tests/bug38942.phpt +++ b/ext/reflection/tests/bug38942.phpt @@ -1,36 +1,36 @@ ---TEST--
-Bug #38942 (Double old-style-ctor inheritance)
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-class foo {
- public function foo() {}
-}
-
-class bar extends foo {
-}
-ReflectionClass::export("bar");
-?>
---EXPECTF--
-Class [ <user> class bar extends foo ] {
- @@ %sbug38942.php 6-7
-
- - Constants [0] {
- }
-
- - Static properties [0] {
- }
-
- - Static methods [0] {
- }
-
- - Properties [0] {
- }
-
- - Methods [1] {
- Method [ <user, inherits foo, ctor> public method foo ] {
- @@ %sbug38942.php 3 - 3
- }
- }
-}
+--TEST-- +Bug #38942 (Double old-style-ctor inheritance) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class foo { + public function foo() {} +} + +class bar extends foo { +} +ReflectionClass::export("bar"); +?> +--EXPECTF-- +Class [ <user> class bar extends foo ] { + @@ %sbug38942.php 6-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user, inherits foo, ctor> public method foo ] { + @@ %sbug38942.php 3 - 3 + } + } +} diff --git a/ext/reflection/tests/bug45139.phpt b/ext/reflection/tests/bug45139.phpt new file mode 100644 index 000000000..6aa84263c --- /dev/null +++ b/ext/reflection/tests/bug45139.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #45139 (ReflectionProperty returns incorrect declaring class) +--FILE-- +<?php + +class A { + private $foo; +} + +class B extends A { + protected $bar; + private $baz; + private $quux; +} + +class C extends B { + public $foo; + private $baz; + protected $quux; +} + +$rc = new ReflectionClass('C'); +$rp = $rc->getProperty('foo'); +var_dump($rp->getDeclaringClass()->getName()); // c + +$rc = new ReflectionClass('A'); +$rp = $rc->getProperty('foo'); +var_dump($rp->getDeclaringClass()->getName()); // A + +$rc = new ReflectionClass('B'); +$rp = $rc->getProperty('bar'); +var_dump($rp->getDeclaringClass()->getName()); // B + +$rc = new ReflectionClass('C'); +$rp = $rc->getProperty('bar'); +var_dump($rp->getDeclaringClass()->getName()); // B + +$rc = new ReflectionClass('C'); +$rp = $rc->getProperty('baz'); +var_dump($rp->getDeclaringClass()->getName()); // C + +$rc = new ReflectionClass('B'); +$rp = $rc->getProperty('baz'); +var_dump($rp->getDeclaringClass()->getName()); // B + +$rc = new ReflectionClass('C'); +$rp = $rc->getProperty('quux'); +var_dump($rp->getDeclaringClass()->getName()); // C + +?> +--EXPECT-- +string(1) "C" +string(1) "A" +string(1) "B" +string(1) "B" +string(1) "C" +string(1) "B" +string(1) "C" diff --git a/ext/reflection/tests/bug45765.phpt b/ext/reflection/tests/bug45765.phpt new file mode 100644 index 000000000..b0c1be2c4 --- /dev/null +++ b/ext/reflection/tests/bug45765.phpt @@ -0,0 +1,82 @@ +--TEST-- +Fixed bug #45765 (ReflectionObject with default parameters of self::xxx cause an error) +--FILE-- +<?php + +class foo2 { + const BAR = 'foobar'; +} + +class foo extends foo2 { + const BAR = "foo's bar"; + + function test($a = self::BAR) { + } + + function test2($a = parent::BAR) { + } + + function test3($a = foo::BAR) { + } + + function test4($a = foo2::BAR) { + } +} + +ReflectionObject::export(new foo); + +?> +--EXPECTF-- +Object of class [ <user> class foo extends foo2 ] { + @@ %s 7-21 + + - Constants [1] { + Constant [ string BAR ] { foo's bar } + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Dynamic properties [0] { + } + + - Methods [4] { + Method [ <user> public method test ] { + @@ %s 10 - 11 + + - Parameters [1] { + Parameter #0 [ <optional> $a = 'foo's bar' ] + } + } + + Method [ <user> public method test2 ] { + @@ %s 13 - 14 + + - Parameters [1] { + Parameter #0 [ <optional> $a = 'foobar' ] + } + } + + Method [ <user> public method test3 ] { + @@ %s 16 - 17 + + - Parameters [1] { + Parameter #0 [ <optional> $a = 'foo's bar' ] + } + } + + Method [ <user> public method test4 ] { + @@ %s 19 - 20 + + - Parameters [1] { + Parameter #0 [ <optional> $a = 'foobar' ] + } + } + } +} diff --git a/ext/reflection/tests/bug46064.phpt b/ext/reflection/tests/bug46064.phpt new file mode 100644 index 000000000..58b732f31 --- /dev/null +++ b/ext/reflection/tests/bug46064.phpt @@ -0,0 +1,74 @@ +--TEST-- +Bug #46064 (Exception when creating ReflectionProperty object on dynamicly created property) +--FILE-- +<?php + +class x { + public $zzz = 2; +} + +$o = new x; +$o->z = 1000; +$o->zzz = 3; + +var_dump($h = new reflectionproperty($o, 'z')); +var_dump($h->isDefault()); +var_dump($h->isPublic()); +var_dump($h->isStatic()); +var_dump($h->getName()); +var_dump(Reflection::getModifierNames($h->getModifiers())); +var_dump($h->getValue($o)); + +print "---------------------------\n"; +try { + var_dump(new reflectionproperty($o, 'zz')); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +var_dump(new reflectionproperty($o, 'zzz')); + +class test { + protected $a = 1; +} + +class bar extends test { + public function __construct() { + $this->foobar = 2; + $this->a = 200; + + $p = new reflectionproperty($this, 'foobar'); + var_dump($p->getValue($this), $p->isDefault(), $p->isPublic()); + } +} + +new bar; + +?> +--EXPECTF-- +object(ReflectionProperty)#2 (2) { + ["name"]=> + string(1) "z" + ["class"]=> + string(1) "x" +} +bool(false) +bool(true) +bool(false) +string(1) "z" +array(1) { + [0]=> + string(6) "public" +} +int(1000) +--------------------------- +string(30) "Property x::$zz does not exist" +object(ReflectionProperty)#3 (2) { + ["name"]=> + string(3) "zzz" + ["class"]=> + string(1) "x" +} +int(2) +bool(false) +bool(true) diff --git a/ext/reflection/tests/bug46064_2.phpt b/ext/reflection/tests/bug46064_2.phpt new file mode 100644 index 000000000..832d13c41 --- /dev/null +++ b/ext/reflection/tests/bug46064_2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Bug #46064.2 (Exception when creating ReflectionProperty object on dynamicly created property) +--FILE-- +<?php + +class foo { +} + +$x = new foo; +$x->test = 2000; + + +$p = new ReflectionObject($x); +var_dump($p->getProperty('test')); + + +class bar { + public function __construct() { + $this->a = 1; + } +} + +class test extends bar { + private $b = 2; + + public function __construct() { + parent::__construct(); + + $p = new reflectionobject($this); + var_dump($h = $p->getProperty('a')); + var_dump($h->isDefault(), $h->isProtected(), $h->isPrivate(), $h->isPublic(), $h->isStatic()); + var_dump($p->getProperties()); + } +} + +new test; + +?> +--EXPECT-- +object(ReflectionProperty)#3 (2) { + ["name"]=> + string(4) "test" + ["class"]=> + string(3) "foo" +} +object(ReflectionProperty)#5 (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "test" +} +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) +array(2) { + [0]=> + &object(ReflectionProperty)#6 (2) { + ["name"]=> + string(1) "b" + ["class"]=> + string(4) "test" + } + [1]=> + &object(ReflectionProperty)#7 (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "test" + } +} diff --git a/ext/reflection/tests/included4.inc b/ext/reflection/tests/included4.inc new file mode 100644 index 000000000..88947251c --- /dev/null +++ b/ext/reflection/tests/included4.inc @@ -0,0 +1,9 @@ +<?php +echo __FILE__ . "\n"; +echo __LINE__ . "\n"; + +function g() { + echo __FILE__ . "\n"; + echo __LINE__ . "\n"; +} +?>
\ No newline at end of file diff --git a/ext/reflection/tests/parameters_001.phpt b/ext/reflection/tests/parameters_001.phpt index 036f11973..62cd069b6 100755 --- a/ext/reflection/tests/parameters_001.phpt +++ b/ext/reflection/tests/parameters_001.phpt @@ -1,40 +1,40 @@ ---TEST--
-ReflectionParameter Check for parameter being optional
---SKIPIF--
-<?php extension_loaded('reflection') or die('skip'); ?>
---FILE--
-<?php
-
-class Test {
- function func($x, $y = NULL){
- }
-}
-
-
-$f = new ReflectionMethod('Test', 'func');
-var_dump($f->getNumberOfParameters());
-var_dump($f->getNumberOfRequiredParameters());
-
-$p = new ReflectionParameter(array('Test', 'func'), 'x');
-var_dump($p->isOptional());
-
-$p = new ReflectionParameter(array('Test', 'func'), 'y');
-var_dump($p->isOptional());
-
-try {
- $p = new ReflectionParameter(array('Test', 'func'), 'z');
- var_dump($p->isOptional());
-}
-catch (Exception $e) {
- var_dump($e->getMessage());
-}
-
-?>
-===DONE===
---EXPECT--
-int(2)
-int(1)
-bool(false)
-bool(true)
-string(54) "The parameter specified by its name could not be found"
-===DONE===
+--TEST-- +ReflectionParameter Check for parameter being optional +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class Test { + function func($x, $y = NULL){ + } +} + + +$f = new ReflectionMethod('Test', 'func'); +var_dump($f->getNumberOfParameters()); +var_dump($f->getNumberOfRequiredParameters()); + +$p = new ReflectionParameter(array('Test', 'func'), 'x'); +var_dump($p->isOptional()); + +$p = new ReflectionParameter(array('Test', 'func'), 'y'); +var_dump($p->isOptional()); + +try { + $p = new ReflectionParameter(array('Test', 'func'), 'z'); + var_dump($p->isOptional()); +} +catch (Exception $e) { + var_dump($e->getMessage()); +} + +?> +===DONE=== +--EXPECT-- +int(2) +int(1) +bool(false) +bool(true) +string(54) "The parameter specified by its name could not be found" +===DONE=== diff --git a/ext/reflection/tests/reflectionClass_FileInfo_error.phpt b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt index a74062a3e..766cdf3b7 100644 --- a/ext/reflection/tests/reflectionClass_FileInfo_error.phpt +++ b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt @@ -1,37 +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
+--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 index 06b68b88f..1a70fe1f5 100644 --- a/ext/reflection/tests/reflectionClass_constructor_001.phpt +++ b/ext/reflection/tests/reflectionClass_constructor_001.phpt @@ -1,33 +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"
-}
+--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 index 97f1b3570..3685c639d 100644 --- a/ext/reflection/tests/reflectionClass_constructor_002.phpt +++ b/ext/reflection/tests/reflectionClass_constructor_002.phpt @@ -1,67 +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) ""
-}
+--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_export_basic1.phpt b/ext/reflection/tests/reflectionClass_export_basic1.phpt new file mode 100644 index 000000000..8729731f5 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_export_basic1.phpt @@ -0,0 +1,62 @@ +--TEST-- +ReflectionClass::export() - various parameters +--FILE-- +<?php +Class A { + public function privf(Exception $a) {} + public function pubf(A $a, + $b, + C $c = null, + $d = K, + $e = "15 chars long -", + $f = null, + $g = false, + array $h = null) {} +} + +Class C extends A { } + +define('K', "16 chars long --"); +ReflectionClass::export("C"); +?> +--EXPECTF-- +Class [ <user> class C extends A ] { + @@ %s 14-14 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ <user, inherits A> public method privf ] { + @@ %s 3 - 3 + + - Parameters [1] { + Parameter #0 [ <required> Exception $a ] + } + } + + Method [ <user, inherits A> public method pubf ] { + @@ %s 4 - 11 + + - Parameters [8] { + Parameter #0 [ <required> A $a ] + Parameter #1 [ <required> $b ] + Parameter #2 [ <optional> C or NULL $c = NULL ] + Parameter #3 [ <optional> $d = '16 chars long -...' ] + Parameter #4 [ <optional> $e = '15 chars long -' ] + Parameter #5 [ <optional> $f = NULL ] + Parameter #6 [ <optional> $g = false ] + Parameter #7 [ <optional> array or NULL $h = NULL ] + } + } + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_export_basic2.phpt b/ext/reflection/tests/reflectionClass_export_basic2.phpt new file mode 100644 index 000000000..b6644883e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_export_basic2.phpt @@ -0,0 +1,54 @@ +--TEST-- +ReflectionClass::export() - ensure inherited private props are hidden. +--FILE-- +<?php +Class c { + private $a; + static private $b; +} + +class d extends c {} + +ReflectionClass::export("c"); +ReflectionClass::export("d"); +?> +--EXPECTF-- +Class [ <user> class c ] { + @@ %s 2-5 + + - Constants [0] { + } + + - Static properties [1] { + Property [ private static $b ] + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ <default> private $a ] + } + + - Methods [0] { + } +} + +Class [ <user> class d extends c ] { + @@ %s 7-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt index d0909ec4f..6e051113d 100644 --- a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt +++ b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt @@ -1,41 +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)
+--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 index a1e300519..907d6d8b7 100644 --- a/ext/reflection/tests/reflectionClass_getConstant_error.phpt +++ b/ext/reflection/tests/reflectionClass_getConstant_error.phpt @@ -1,37 +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
+--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_getConstructor_basic.phpt b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt index 59c87ad66..f3881c56d 100644 --- a/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt +++ b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt @@ -1,82 +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
+--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 index 53d19b5ac..8892b1d6b 100644 --- a/ext/reflection/tests/reflectionClass_getConstructor_error.phpt +++ b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt @@ -1,24 +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
+--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_getExtensionName_basic.phpt b/ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt new file mode 100644 index 000000000..7813cca31 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::getExtensionName() method - basic test for getExtensionName() method +--SKIPIF-- +<?php extension_loaded('reflection') && extension_loaded('dom') or die('skip - reflection or dom extension not loaded'); ?> +--CREDITS-- +Rein Velt <rein@velt.org> +#testFest Roosendaal 2008-05-10 +--FILE-- +<?php + $rc=new reflectionClass('domDocument'); + var_dump( $rc->getExtensionName()) ; +?> +--EXPECT-- +string(3) "dom" diff --git a/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt b/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt new file mode 100644 index 000000000..35372c4f8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::getExtensionName() method - variation test for getExtensionName() +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip - reflection extension not loaded'); ?> +--CREDITS-- +Rein Velt <rein@velt.org> +#testFest Roosendaal 2008-05-10 +--FILE-- +<?php + + class myClass + { + public $varX; + public $varY; + } + $rc=new reflectionClass('myClass'); + var_dump( $rc->getExtensionName()) ; +?> +--EXPECT-- +bool(false)
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getExtension_basic.phpt b/ext/reflection/tests/reflectionClass_getExtension_basic.phpt new file mode 100644 index 000000000..efc1ed8ee --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtension_basic.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getExtension() method - basic test for getExtension() method +--SKIPIF-- +<?php extension_loaded('reflection') && extension_loaded('dom') or die('skip - reflection or dom extension not loaded'); ?> +--CREDITS-- +Rein Velt <rein@velt.org> +#testFest Roosendaal 2008-05-10 +--FILE-- +<?php + $rc=new reflectionClass('domDocument'); + var_dump($rc->getExtension()) ; +?> +--EXPECTF-- +object(ReflectionExtension)#%d (1) { + ["name"]=> + string(3) "dom" +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getExtension_variation.phpt b/ext/reflection/tests/reflectionClass_getExtension_variation.phpt new file mode 100644 index 000000000..f2272777a --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtension_variation.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::getExtension() method - variation test for getExtension() +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip - reflection extension not loaded'); ?> +--CREDITS-- +Rein Velt <rein@velt.org> +#testFest Roosendaal 2008-05-10 +--FILE-- +<?php + + class myClass + { + public $varX; + public $varY; + } + $rc=new reflectionClass('myClass'); + var_dump( $rc->getExtension()) ; +?> +--EXPECT-- +NULL
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt b/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt new file mode 100644 index 000000000..abbaa35f5 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +ReflectionClass::getInterfaceNames() +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip - reflection extension not loaded'); ?> +--CREDITS-- +Michelangelo van Dam <dragonbe@gmail.com> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php +interface Foo { } + +interface Bar { } + +class Baz implements Foo, Bar { } + +$rc1 = new ReflectionClass("Baz"); +var_dump($rc1->getInterfaceNames()); +?> +--EXPECT-- +array(2) { + [0]=> + string(3) "Foo" + [1]=> + string(3) "Bar" +} diff --git a/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt new file mode 100644 index 000000000..33a2539b9 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClass::getModifiers() +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +--FILE-- +<?php + +class a {} +abstract class b {} +final class c {} +interface d {} +class e implements d {} +interface f extends d {} +class g extends b {} + +function dump_modifiers($class) { + $obj = new ReflectionClass($class); + var_dump($obj->getModifiers()); +} + +dump_modifiers('a'); +dump_modifiers('b'); +dump_modifiers('c'); +dump_modifiers('d'); +dump_modifiers('e'); +dump_modifiers('f'); +dump_modifiers('g'); + +?> +--EXPECT-- +int(0) +int(32) +int(64) +int(128) +int(0) +int(128) +int(0)
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getParentClass.phpt b/ext/reflection/tests/reflectionClass_getParentClass.phpt new file mode 100644 index 000000000..46884ca2b --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getParentClass.phpt @@ -0,0 +1,21 @@ +--TEST-- +ReflectionClass::getParentClass() +--CREDITS-- +Michelangelo van Dam <dragonbe@gmail.com> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php + +class Foo {} + +class Bar extends Foo {} + +$rc1 = new ReflectionClass("Bar"); +var_dump($rc1->getParentClass()); +?> + +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(3) "Foo" +} diff --git a/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt b/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt new file mode 100644 index 000000000..49570150c --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::hasConstant() +--CREDIT-- +Marc Veldman <marc@ibuildings.nl> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php +//New instance of class C - defined below +$rc = new ReflectionClass("C"); + +//Check if C has constant foo +var_dump($rc->hasConstant('foo')); + +//C should not have constant bar +var_dump($rc->hasConstant('bar')); + +Class C { + const foo=1; +} +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt b/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt new file mode 100644 index 000000000..3ef5ac920 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +ReflectionClass::hasMethod() +--CREDIT-- +Marc Veldman <marc@ibuildings.nl> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php +//New instance of class C - defined below +$rc = new ReflectionClass("C"); + +//Check if C has public method publicFoo +var_dump($rc->hasMethod('publicFoo')); + +//Check if C has protected method protectedFoo +var_dump($rc->hasMethod('protectedFoo')); + +//Check if C has private method privateFoo +var_dump($rc->hasMethod('privateFoo')); + +//Check if C has static method staticFoo +var_dump($rc->hasMethod('staticFoo')); + +//C should not have method bar +var_dump($rc->hasMethod('bar')); + +//Method names are case insensitive +var_dump($rc->hasMethod('PUBLICfOO')); + +Class C { + public function publicFoo() + { + return true; + } + + protected function protectedFoo() + { + return true; + } + + private function privateFoo() + { + return true; + } + + static function staticFoo() + { + return true; + } +} +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt b/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt new file mode 100644 index 000000000..b3264e01e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionClass::hasProperty() +--CREDIT-- +Marc Veldman <marc@ibuildings.nl> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php +//New instance of class C - defined below +$rc = new ReflectionClass("C"); + +//Check if C has public property publicFoo +var_dump($rc->hasProperty('publicFoo')); + +//Check if C has protected property protectedFoo +var_dump($rc->hasProperty('protectedFoo')); + +//Check if C has private property privateFoo +var_dump($rc->hasProperty('privateFoo')); + +//Check if C has static property staticFoo +var_dump($rc->hasProperty('staticFoo')); + +//C should not have property bar +var_dump($rc->hasProperty('bar')); + +Class C { + public $publicFoo; + protected $protectedFoo; + private $privateFoo; + public static $staticFoo; +} +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt b/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt new file mode 100644 index 000000000..7a3d577ef --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::isAbstract() method +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip - reflection extension not loaded'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php + +class TestClass {} +abstract class TestAbstractClass {} + +$testClass = new ReflectionClass('TestClass'); +$abstractClass = new ReflectionClass('TestAbstractClass'); + +var_dump($testClass->isAbstract()); +var_dump($abstractClass->isAbstract()); + +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isFinal_basic.phpt b/ext/reflection/tests/reflectionClass_isFinal_basic.phpt new file mode 100644 index 000000000..efa131724 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isFinal_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::isFinal() method +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip - reflection extension not loaded'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php + +class TestClass {} +final class TestFinalClass {} + +$normalClass = new ReflectionClass('TestClass'); +$finalClass = new ReflectionClass('TestFinalClass'); + +var_dump($normalClass->isFinal()); +var_dump($finalClass->isFinal()); + +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInterface_basic.phpt b/ext/reflection/tests/reflectionClass_isInterface_basic.phpt new file mode 100644 index 000000000..2870725e8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInterface_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::isInterface() method +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +#testfest roosendaal on 2008-05-10 +--FILE-- +<?php + +interface TestInterface {} +class TestClass {} +interface DerivedInterface extends TestInterface {} + +$reflectionClass = new ReflectionClass('TestInterface'); +$reflectionClass2 = new ReflectionClass('TestClass'); +$reflectionClass3 = new ReflectionClass('DerivedInterface'); + +var_dump($reflectionClass->isInterface()); +var_dump($reflectionClass2->isInterface()); +var_dump($reflectionClass3->isInterface()); + +?> +--EXPECT-- +bool(true) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt b/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt new file mode 100644 index 000000000..3e1228af2 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionClass::isIterateable() basic +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com>, Marc Veldman <marc@ibuildings.nl> +--FILE-- +<?php + +class IteratorClass implements Iterator { + public function __construct() { } + public function key() {} + public function current() {} + function next() {} + function valid() {} + function rewind() {} +} +class DerivedClass extends IteratorClass {} +class NonIterator {} + +function dump_iterateable($class) { + $reflection = new ReflectionClass($class); + var_dump($reflection->isIterateable()); +} + +$classes = array("ArrayObject", "IteratorClass", "DerivedClass", "NonIterator"); +foreach ($classes as $class) { + echo "Is $class iterateable? "; + dump_iterateable($class); +} +?> +--EXPECT-- +Is ArrayObject iterateable? bool(true) +Is IteratorClass iterateable? bool(true) +Is DerivedClass iterateable? bool(true) +Is NonIterator iterateable? bool(false) diff --git a/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt b/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt new file mode 100644 index 000000000..6d737bb89 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::isIterateable() variations +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +--FILE-- +<?php + +class BasicClass {} + +function dump_iterateable($obj) +{ + $reflection = new ReflectionClass($obj); + var_dump($reflection->isIterateable()); +} + +$basicClass = new BasicClass(); +$stdClass = new StdClass(); + +dump_iterateable($basicClass); +dump_iterateable($stdClass); + +?> +--EXPECT-- +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionObject___toString_basic1.phpt b/ext/reflection/tests/reflectionObject___toString_basic1.phpt new file mode 100644 index 000000000..fefa220c9 --- /dev/null +++ b/ext/reflection/tests/reflectionObject___toString_basic1.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionObject::__toString() : very basic test with no dynamic properties +--FILE-- +<?php + +class Foo { + public $bar = 1; +} +$f = new foo; + +echo new ReflectionObject($f); + +?> +--EXPECTF-- +Object of class [ <user> class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ <default> public $bar ] + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject___toString_basic2.phpt b/ext/reflection/tests/reflectionObject___toString_basic2.phpt new file mode 100644 index 000000000..332386afd --- /dev/null +++ b/ext/reflection/tests/reflectionObject___toString_basic2.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionObject::__toString() : very basic test with dynamic properties +--FILE-- +<?php + +class Foo { + public $bar = 1; +} +$f = new foo; +$f->dynProp = 'hello'; +$f->dynProp2 = 'hello again'; +echo new ReflectionObject($f); + +?> +--EXPECTF-- +Object of class [ <user> class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ <default> public $bar ] + } + + - Dynamic properties [2] { + Property [ <dynamic> public $dynProp ] + Property [ <dynamic> public $dynProp2 ] + } + + - Methods [0] { + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic1.phpt b/ext/reflection/tests/reflectionObject_export_basic1.phpt new file mode 100644 index 000000000..f7dfef867 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic1.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionObject::export() : very basic test with no dynamic properties +--FILE-- +<?php + +class Foo { + public $bar = 1; +} +$f = new foo; + +ReflectionObject::export($f); + +?> +--EXPECTF-- +Object of class [ <user> class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ <default> public $bar ] + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic2.phpt b/ext/reflection/tests/reflectionObject_export_basic2.phpt new file mode 100644 index 000000000..277f06eaf --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic2.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionObject::export() : very basic test with dynamic properties +--FILE-- +<?php + +class Foo { + public $bar = 1; +} +$f = new foo; +$f->dynProp = 'hello'; +$f->dynProp2 = 'hello again'; +ReflectionObject::export($f); + +?> +--EXPECTF-- +Object of class [ <user> class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ <default> public $bar ] + } + + - Dynamic properties [2] { + Property [ <dynamic> public $dynProp ] + Property [ <dynamic> public $dynProp2 ] + } + + - Methods [0] { + } +}
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic3.phpt b/ext/reflection/tests/reflectionObject_export_basic3.phpt new file mode 100644 index 000000000..7c1da34c9 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic3.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionObject::export() - ensure dynamic property with same name as inherited private property is shown. +--FILE-- +<?php +class C { + private $p = 1; +} + +class D extends C{ +} + +$Obj = new D; +$Obj->p = 'value'; +ReflectionObject::export($Obj) +?> +--EXPECTF-- +Object of class [ <user> class D extends C ] { + @@ %s 6-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +} + diff --git a/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt new file mode 100644 index 000000000..3118c17be --- /dev/null +++ b/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt @@ -0,0 +1,31 @@ +--TEST-- +ReflectionParameter::__construct(): Invalid method as constructor +--FILE-- +<?php + +// Invalid class name +try { + new ReflectionParameter (array ('A', 'b'), 0); +} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } + +// Invalid class method +try { + new ReflectionParameter (array ('C', 'b'), 0); +} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } + +// Invalid object method +try { + new ReflectionParameter (array (new C, 'b'), 0); +} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } + +echo "Done.\n"; + +class C { +} + +?> +--EXPECTF-- +Class A does not exist +Method C::b() does not exist +Method C::b() does not exist +Done. diff --git a/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt b/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt new file mode 100644 index 000000000..d61480377 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt @@ -0,0 +1,58 @@ +--TEST-- +ReflectionProperty::__construct(): ensure inherited private props can't be accessed through ReflectionProperty. +--FILE-- +<?php + +class C { + private $p = 1; + + static function testFromC() { + try { + $rp = new ReflectionProperty("D", "p"); + var_dump($rp); + } catch (Exception $e) { + echo $e->getMessage(); + } + } +} + +class D extends C{ + static function testFromD() { + try { + $rp = new ReflectionProperty("D", "p"); + var_dump($rp); + } catch (Exception $e) { + echo $e->getMessage(); + } + } +} + +echo "--> Reflect inherited private from global scope:\n"; +try { + $rp = new ReflectionProperty("D", "p"); + var_dump($rp); +} catch (Exception $e) { + echo $e->getMessage(); +} + +echo "\n\n--> Reflect inherited private from declaring scope:\n"; +C::testFromC(); + +echo "\n\n--> Reflect inherited private from declaring scope via subclass:\n"; +D::testFromC(); + +echo "\n\n--> Reflect inherited private from subclass:\n"; +D::testFromD(); +?> +--EXPECTF-- +--> Reflect inherited private from global scope: +Property D::$p does not exist + +--> Reflect inherited private from declaring scope: +Property D::$p does not exist + +--> Reflect inherited private from declaring scope via subclass: +Property D::$p does not exist + +--> Reflect inherited private from subclass: +Property D::$p does not exist
\ No newline at end of file |
