com php-src: Switch to hasTypeAnnotation()/getTypeAnnotation(): ext/reflection/php_reflection.c ext/reflection/tests/Refl
ectionExtension_getClasses_basic.phpt ext/reflection/te sts/parameters_typehint.phpt
| From: | Matteo Beccati | Date: | Fri, 30 May 2014 00:33:12 +0000 |
| Subject: | com php-src: Switch to hasTypeAnnotation()/getTypeAnnotation(): ext/reflection/php_reflection.c ext/reflection/tests/Refl ectionExtension_getClasses_basic.phpt ext/reflection/te sts/parameters_typehint.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84916@lists.php.net to get a copy of this message | ||
Commit: acb70c8378e093b295287f2640b233a4cfe3e8ec
Author: Sara Golemon <pollita@php.net> Thu, 29 May 2014 15:53:59 -0700
Parents: d352793a69eb549ffe4b04c4b5dedae2cd4ed831
Branches: scalar_hints_with_reflection
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=acb70c8378e093b295287f2640b233a4cfe3e8ec
Log:
Switch to hasTypeAnnotation()/getTypeAnnotation()
Introduce ReflectionTypeAnnotation class.
Changed paths:
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt
M ext/reflection/tests/parameters_typehint.phpt
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index de1a622..1b687c8 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -57,6 +57,7 @@ PHPAPI zend_class_entry *reflection_ptr; PHPAPI zend_class_entry *reflection_function_abstract_ptr; PHPAPI zend_class_entry *reflection_function_ptr; PHPAPI zend_class_entry *reflection_parameter_ptr; +PHPAPI zend_class_entry *reflection_typeannotation_ptr; PHPAPI zend_class_entry *reflection_class_ptr; PHPAPI zend_class_entry *reflection_object_ptr; PHPAPI zend_class_entry *reflection_method_ptr; @@ -194,10 +195,16 @@ typedef struct _parameter_reference { zend_function *fptr; } parameter_reference; +/* Struct for type annotations */ +typedef struct _typeannotation_reference { + struct _zend_arg_info *arg_info; +} typeannotation_reference; + typedef enum { REF_TYPE_OTHER, /* Must be 0 */ REF_TYPE_FUNCTION, REF_TYPE_PARAMETER, + REF_TYPE_ANNOTATION, REF_TYPE_PROPERTY, REF_TYPE_DYNAMIC_PROPERTY } reflection_type_t; @@ -292,6 +299,8 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */ case REF_TYPE_PARAMETER: reference = (parameter_reference*)intern->ptr; _free_function(reference->fptr TSRMLS_CC); + /* fallthrough */ + case REF_TYPE_ANNOTATION: efree(intern->ptr); break; case REF_TYPE_FUNCTION: @@ -1264,6 +1273,26 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje } /* }}} */ +/* {{{ reflection_typeannotation_factory */ +static void reflection_typeannotation_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zval *object TSRMLS_DC) +{ + reflection_object *intern; + typeannotation_reference *reference; + + if (closure_object) { + Z_ADDREF_P(closure_object); + } + reflection_instantiate(reflection_typeannotation_ptr, object TSRMLS_CC); + intern = (reflection_object*) zend_object_store_get_object(object TSRMLS_CC); + reference = (typeannotation_reference*) emalloc(sizeof(typeannotation_reference)); + reference->arg_info = arg_info; + intern->ptr = reference; + intern->ref_type = REF_TYPE_ANNOTATION; + intern->ce = fptr->common.scope; + intern->obj = closure_object; +} +/* }}} */ + /* {{{ reflection_function_factory */ static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object TSRMLS_DC) { @@ -2434,9 +2463,9 @@ ZEND_METHOD(reflection_parameter, getClass) } /* }}} */ -/* {{{ proto public bool ReflectionParameter::hasTypehint() +/* {{{ proto public bool ReflectionParameter::hasTypeAnnotation() Rethern whether parameter has a type hint */ -ZEND_METHOD(reflection_parameter, hasTypehint) +ZEND_METHOD(reflection_parameter, hasTypeAnnotation) { reflection_object *intern; parameter_reference *param; @@ -2450,9 +2479,9 @@ ZEND_METHOD(reflection_parameter, hasTypehint) } /* }}} */ -/* {{{ proto public string ReflectionParameter::getTypehintText() +/* {{{ proto public string ReflectionParameter::getTypeAnnotation() Returns the typehint associated with the parameter */ -ZEND_METHOD(reflection_parameter, getTypehintText) +ZEND_METHOD(reflection_parameter, getTypeAnnotation) { reflection_object *intern; parameter_reference *param; @@ -2462,17 +2491,10 @@ ZEND_METHOD(reflection_parameter, getTypehintText) } GET_REFLECTION_OBJECT_PTR(param); - switch (param->arg_info->type_hint) { - case IS_ARRAY: - RETURN_STRINGL("array", sizeof("array") - 1, 1); - case IS_CALLABLE: - RETURN_STRINGL("callable", sizeof("callable") - 1, 1); - case IS_OBJECT: - RETURN_STRINGL(param->arg_info->class_name, - param->arg_info->class_name_len, 1); - default: - RETURN_EMPTY_STRING(); + if (!param->arg_info->type_hint) { + RETURN_NULL(); } + reflection_typeannotation_factory(param->fptr, intern->obj, param->arg_info, return_value TSRMLS_CC); } /* }}} */ @@ -2709,6 +2731,78 @@ ZEND_METHOD(reflection_parameter, isVariadic) } /* }}} */ +/* {{{ proto public bool ReflectionTypeAnnotation::isArray() + Returns whether parameter MUST be an array */ +ZEND_METHOD(reflection_typeannotation, isArray) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint == IS_ARRAY); +} +/* }}} */ + +/* {{{ proto public bool ReflectionTypeAnnotation::isCallable() + Returns whether parameter MUST be callable */ +ZEND_METHOD(reflection_typeannotation, isCallable) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint == IS_CALLABLE); +} +/* }}} */ + +/* {{{ proto public bool ReflectionTypeAnnotation::isNullable() + Returns whether parameter MAY be null */ +ZEND_METHOD(reflection_typeannotation, isNullable) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->allow_null); +} +/* }}} */ + +/* {{{ proto public string ReflectionTypeAnnotation::__toString() + Return the text of the type annotation */ +ZEND_METHOD(reflection_typeannotation, __toString) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + switch (param->arg_info->type_hint) { + case IS_ARRAY: RETURN_STRINGL("array", sizeof("array") - 1, 1); + case IS_CALLABLE: RETURN_STRINGL("callable", sizeof("callable") - 1, 1); + case IS_OBJECT: RETURN_STRINGL(param->arg_info->class_name, + param->arg_info->class_name_len, 1); + default: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unknown type annotation: %d", (int)param->arg_info->type_hint); + RETURN_EMPTY_STRING(); + } +} +/* }}} */ + /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_method, export) @@ -6068,8 +6162,8 @@ static const zend_function_entry reflection_parameter_functions[] = { ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0) - ZEND_ME(reflection_parameter, hasTypehint, arginfo_reflection__void, 0) - ZEND_ME(reflection_parameter, getTypehintText, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, hasTypeAnnotation, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, getTypeAnnotation, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0) @@ -6083,6 +6177,15 @@ static const zend_function_entry reflection_parameter_functions[] = { PHP_FE_END }; +static const zend_function_entry reflection_typeannotation_functions[] = { + ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) + ZEND_ME(reflection_typeannotation, isArray, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, isCallable, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, isNullable, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, __toString, arginfo_reflection__void, 0) + PHP_FE_END +}; + ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_extension_export, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, return) @@ -6190,6 +6293,11 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_register_implement(reflection_parameter_ptr, reflector_ptr TSRMLS_CC); zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionTypeAnnotation", reflection_typeannotation_functions); + _reflection_entry.create_object = reflection_objects_new; + reflection_typeannotation_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); + reflection_register_implement(reflection_typeannotation_ptr, reflector_ptr TSRMLS_CC); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions); _reflection_entry.create_object = reflection_objects_new; reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index 5df9e08..2fbb0e7 100644 --- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt @@ -9,7 +9,7 @@ var_dump($ext->getClasses()); ?> ==DONE== --EXPECT-- -array(12) { +array(13) { ["ReflectionException"]=> &object(ReflectionClass)#2 (1) { ["name"]=> @@ -40,33 +40,38 @@ array(12) { ["name"]=> string(19) "ReflectionParameter" } - ["ReflectionMethod"]=> + ["ReflectionTypeAnnotation"]=> &object(ReflectionClass)#8 (1) { ["name"]=> + string(24) "ReflectionTypeAnnotation" + } + ["ReflectionMethod"]=> + &object(ReflectionClass)#9 (1) { + ["name"]=> string(16) "ReflectionMethod" } ["ReflectionClass"]=> - &object(ReflectionClass)#9 (1) { + &object(ReflectionClass)#10 (1) { ["name"]=> string(15) "ReflectionClass" } ["ReflectionObject"]=> - &object(ReflectionClass)#10 (1) { + &object(ReflectionClass)#11 (1) { ["name"]=> string(16) "ReflectionObject" } ["ReflectionProperty"]=> - &object(ReflectionClass)#11 (1) { + &object(ReflectionClass)#12 (1) { ["name"]=> string(18) "ReflectionProperty" } ["ReflectionExtension"]=> - &object(ReflectionClass)#12 (1) { + &object(ReflectionClass)#13 (1) { ["name"]=> string(19) "ReflectionExtension" } ["ReflectionZendExtension"]=> - &object(ReflectionClass)#13 (1) { + &object(ReflectionClass)#14 (1) { ["name"]=> string(23) "ReflectionZendExtension" } diff --git a/ext/reflection/tests/parameters_typehint.phpt b/ext/reflection/tests/parameters_typehint.phpt index 04aaeed..61ea5b5 100644 --- a/ext/reflection/tests/parameters_typehint.phpt +++ b/ext/reflection/tests/parameters_typehint.phpt @@ -1,25 +1,45 @@ --TEST-- -ReflectionParameter::hasTypehint() / getTypehintText() +ReflectionParameter::hasTypeAnnotation() / getTypeAnnotation() --FILE-- <?php -function foo(stdClass $a, array $b, callable $c, $d) { } +function foo(stdClass $a, array $b, callable $c, stdClass $d = null, $e = null) { } $rf = new ReflectionFunction('foo'); foreach ($rf->getParameters() as $idx => $rp) { echo "** Parameter $idx\n"; - var_dump($rp->hasTypehint()); - var_dump($rp->getTypehintText()); + var_dump($rp->hasTypeAnnotation()); + $ra = $rp->getTypeAnnotation(); + if ($ra) { + var_dump($ra->isArray()); + var_dump($ra->isCallable()); + var_dump($ra->isNullable()); + var_dump((string)$ra); + } } --EXPECT-- ** Parameter 0 bool(true) +bool(false) +bool(false) +bool(false) string(8) "stdClass" ** Parameter 1 bool(true) +bool(true) +bool(false) +bool(false) string(5) "array" ** Parameter 2 bool(true) +bool(false) +bool(true) +bool(false) string(8) "callable" ** Parameter 3 +bool(true) +bool(false) +bool(false) +bool(true) +string(8) "stdClass" +** Parameter 4 bool(false) -string(0) ""
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index de1a622..1b687c8 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -57,6 +57,7 @@ PHPAPI zend_class_entry *reflection_ptr; PHPAPI zend_class_entry *reflection_function_abstract_ptr; PHPAPI zend_class_entry *reflection_function_ptr; PHPAPI zend_class_entry *reflection_parameter_ptr; +PHPAPI zend_class_entry *reflection_typeannotation_ptr; PHPAPI zend_class_entry *reflection_class_ptr; PHPAPI zend_class_entry *reflection_object_ptr; PHPAPI zend_class_entry *reflection_method_ptr; @@ -194,10 +195,16 @@ typedef struct _parameter_reference { zend_function *fptr; } parameter_reference; +/* Struct for type annotations */ +typedef struct _typeannotation_reference { + struct _zend_arg_info *arg_info; +} typeannotation_reference; + typedef enum { REF_TYPE_OTHER, /* Must be 0 */ REF_TYPE_FUNCTION, REF_TYPE_PARAMETER, + REF_TYPE_ANNOTATION, REF_TYPE_PROPERTY, REF_TYPE_DYNAMIC_PROPERTY } reflection_type_t; @@ -292,6 +299,8 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */ case REF_TYPE_PARAMETER: reference = (parameter_reference*)intern->ptr; _free_function(reference->fptr TSRMLS_CC); + /* fallthrough */ + case REF_TYPE_ANNOTATION: efree(intern->ptr); break; case REF_TYPE_FUNCTION: @@ -1264,6 +1273,26 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje } /* }}} */ +/* {{{ reflection_typeannotation_factory */ +static void reflection_typeannotation_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zval *object TSRMLS_DC) +{ + reflection_object *intern; + typeannotation_reference *reference; + + if (closure_object) { + Z_ADDREF_P(closure_object); + } + reflection_instantiate(reflection_typeannotation_ptr, object TSRMLS_CC); + intern = (reflection_object*) zend_object_store_get_object(object TSRMLS_CC); + reference = (typeannotation_reference*) emalloc(sizeof(typeannotation_reference)); + reference->arg_info = arg_info; + intern->ptr = reference; + intern->ref_type = REF_TYPE_ANNOTATION; + intern->ce = fptr->common.scope; + intern->obj = closure_object; +} +/* }}} */ + /* {{{ reflection_function_factory */ static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object TSRMLS_DC) { @@ -2434,9 +2463,9 @@ ZEND_METHOD(reflection_parameter, getClass) } /* }}} */ -/* {{{ proto public bool ReflectionParameter::hasTypehint() +/* {{{ proto public bool ReflectionParameter::hasTypeAnnotation() Rethern whether parameter has a type hint */ -ZEND_METHOD(reflection_parameter, hasTypehint) +ZEND_METHOD(reflection_parameter, hasTypeAnnotation) { reflection_object *intern; parameter_reference *param; @@ -2450,9 +2479,9 @@ ZEND_METHOD(reflection_parameter, hasTypehint) } /* }}} */ -/* {{{ proto public string ReflectionParameter::getTypehintText() +/* {{{ proto public string ReflectionParameter::getTypeAnnotation() Returns the typehint associated with the parameter */ -ZEND_METHOD(reflection_parameter, getTypehintText) +ZEND_METHOD(reflection_parameter, getTypeAnnotation) { reflection_object *intern; parameter_reference *param; @@ -2462,17 +2491,10 @@ ZEND_METHOD(reflection_parameter, getTypehintText) } GET_REFLECTION_OBJECT_PTR(param); - switch (param->arg_info->type_hint) { - case IS_ARRAY: - RETURN_STRINGL("array", sizeof("array") - 1, 1); - case IS_CALLABLE: - RETURN_STRINGL("callable", sizeof("callable") - 1, 1); - case IS_OBJECT: - RETURN_STRINGL(param->arg_info->class_name, - param->arg_info->class_name_len, 1); - default: - RETURN_EMPTY_STRING(); + if (!param->arg_info->type_hint) { + RETURN_NULL(); } + reflection_typeannotation_factory(param->fptr, intern->obj, param->arg_info, return_value TSRMLS_CC); } /* }}} */ @@ -2709,6 +2731,78 @@ ZEND_METHOD(reflection_parameter, isVariadic) } /* }}} */ +/* {{{ proto public bool ReflectionTypeAnnotation::isArray() + Returns whether parameter MUST be an array */ +ZEND_METHOD(reflection_typeannotation, isArray) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint == IS_ARRAY); +} +/* }}} */ + +/* {{{ proto public bool ReflectionTypeAnnotation::isCallable() + Returns whether parameter MUST be callable */ +ZEND_METHOD(reflection_typeannotation, isCallable) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint == IS_CALLABLE); +} +/* }}} */ + +/* {{{ proto public bool ReflectionTypeAnnotation::isNullable() + Returns whether parameter MAY be null */ +ZEND_METHOD(reflection_typeannotation, isNullable) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->allow_null); +} +/* }}} */ + +/* {{{ proto public string ReflectionTypeAnnotation::__toString() + Return the text of the type annotation */ +ZEND_METHOD(reflection_typeannotation, __toString) +{ + reflection_object *intern; + typeannotation_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + switch (param->arg_info->type_hint) { + case IS_ARRAY: RETURN_STRINGL("array", sizeof("array") - 1, 1); + case IS_CALLABLE: RETURN_STRINGL("callable", sizeof("callable") - 1, 1); + case IS_OBJECT: RETURN_STRINGL(param->arg_info->class_name, + param->arg_info->class_name_len, 1); + default: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unknown type annotation: %d", (int)param->arg_info->type_hint); + RETURN_EMPTY_STRING(); + } +} +/* }}} */ + /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_method, export) @@ -6068,8 +6162,8 @@ static const zend_function_entry reflection_parameter_functions[] = { ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0) - ZEND_ME(reflection_parameter, hasTypehint, arginfo_reflection__void, 0) - ZEND_ME(reflection_parameter, getTypehintText, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, hasTypeAnnotation, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, getTypeAnnotation, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0) @@ -6083,6 +6177,15 @@ static const zend_function_entry reflection_parameter_functions[] = { PHP_FE_END }; +static const zend_function_entry reflection_typeannotation_functions[] = { + ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) + ZEND_ME(reflection_typeannotation, isArray, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, isCallable, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, isNullable, arginfo_reflection__void, 0) + ZEND_ME(reflection_typeannotation, __toString, arginfo_reflection__void, 0) + PHP_FE_END +}; + ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_extension_export, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, return) @@ -6190,6 +6293,11 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_register_implement(reflection_parameter_ptr, reflector_ptr TSRMLS_CC); zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionTypeAnnotation", reflection_typeannotation_functions); + _reflection_entry.create_object = reflection_objects_new; + reflection_typeannotation_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); + reflection_register_implement(reflection_typeannotation_ptr, reflector_ptr TSRMLS_CC); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions); _reflection_entry.create_object = reflection_objects_new; reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index 5df9e08..2fbb0e7 100644 --- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt @@ -9,7 +9,7 @@ var_dump($ext->getClasses()); ?> ==DONE== --EXPECT-- -array(12) { +array(13) { ["ReflectionException"]=> &object(ReflectionClass)#2 (1) { ["name"]=> @@ -40,33 +40,38 @@ array(12) { ["name"]=> string(19) "ReflectionParameter" } - ["ReflectionMethod"]=> + ["ReflectionTypeAnnotation"]=> &object(ReflectionClass)#8 (1) { ["name"]=> + string(24) "ReflectionTypeAnnotation" + } + ["ReflectionMethod"]=> + &object(ReflectionClass)#9 (1) { + ["name"]=> string(16) "ReflectionMethod" } ["ReflectionClass"]=> - &object(ReflectionClass)#9 (1) { + &object(ReflectionClass)#10 (1) { ["name"]=> string(15) "ReflectionClass" } ["ReflectionObject"]=> - &object(ReflectionClass)#10 (1) { + &object(ReflectionClass)#11 (1) { ["name"]=> string(16) "ReflectionObject" } ["ReflectionProperty"]=> - &object(ReflectionClass)#11 (1) { + &object(ReflectionClass)#12 (1) { ["name"]=> string(18) "ReflectionProperty" } ["ReflectionExtension"]=> - &object(ReflectionClass)#12 (1) { + &object(ReflectionClass)#13 (1) { ["name"]=> string(19) "ReflectionExtension" } ["ReflectionZendExtension"]=> - &object(ReflectionClass)#13 (1) { + &object(ReflectionClass)#14 (1) { ["name"]=> string(23) "ReflectionZendExtension" } diff --git a/ext/reflection/tests/parameters_typehint.phpt b/ext/reflection/tests/parameters_typehint.phpt index 04aaeed..61ea5b5 100644 --- a/ext/reflection/tests/parameters_typehint.phpt +++ b/ext/reflection/tests/parameters_typehint.phpt @@ -1,25 +1,45 @@ --TEST-- -ReflectionParameter::hasTypehint() / getTypehintText() +ReflectionParameter::hasTypeAnnotation() / getTypeAnnotation() --FILE-- <?php -function foo(stdClass $a, array $b, callable $c, $d) { } +function foo(stdClass $a, array $b, callable $c, stdClass $d = null, $e = null) { } $rf = new ReflectionFunction('foo'); foreach ($rf->getParameters() as $idx => $rp) { echo "** Parameter $idx\n"; - var_dump($rp->hasTypehint()); - var_dump($rp->getTypehintText()); + var_dump($rp->hasTypeAnnotation()); + $ra = $rp->getTypeAnnotation(); + if ($ra) { + var_dump($ra->isArray()); + var_dump($ra->isCallable()); + var_dump($ra->isNullable()); + var_dump((string)$ra); + } } --EXPECT-- ** Parameter 0 bool(true) +bool(false) +bool(false) +bool(false) string(8) "stdClass" ** Parameter 1 bool(true) +bool(true) +bool(false) +bool(false) string(5) "array" ** Parameter 2 bool(true) +bool(false) +bool(true) +bool(false) string(8) "callable" ** Parameter 3 +bool(true) +bool(false) +bool(false) +bool(true) +string(8) "stdClass" +** Parameter 4 bool(false) -string(0) ""