com php-src: Add ReflectionParameter::hasTypehint() and ...::getTypehintText(): ext/reflection/php_reflection.c e
xt/reflection/tests/parameters_typehint.phpt
| From: | Matteo Beccati | Date: | Thu, 29 May 2014 19:49:58 +0000 |
| Subject: | com php-src: Add ReflectionParameter::hasTypehint() and ...::getTypehintText(): ext/reflection/php_reflection.c e xt/reflection/tests/parameters_typehint.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84909@lists.php.net to get a copy of this message | ||
Commit: d352793a69eb549ffe4b04c4b5dedae2cd4ed831
Author: Sara Golemon <pollita@php.net> Thu, 29 May 2014 12:09:37 -0700
Parents: f4a235c541c5d94c88217e1b6707943b7e30cb5a
Branches: scalar_hints_with_reflection
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d352793a69eb549ffe4b04c4b5dedae2cd4ed831
Log:
Add ReflectionParameter::hasTypehint() and ...::getTypehintText()
Changed paths:
M ext/reflection/php_reflection.c
A ext/reflection/tests/parameters_typehint.phpt
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 703e141..de1a622 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2434,6 +2434,48 @@ ZEND_METHOD(reflection_parameter, getClass)
}
/* }}} */
+/* {{{ proto public bool ReflectionParameter::hasTypehint()
+ Rethern whether parameter has a type hint */
+ZEND_METHOD(reflection_parameter, hasTypehint)
+{
+ reflection_object *intern;
+ parameter_reference *param;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+ GET_REFLECTION_OBJECT_PTR(param);
+
+ RETVAL_BOOL(param->arg_info->type_hint != 0);
+}
+/* }}} */
+
+/* {{{ proto public string ReflectionParameter::getTypehintText()
+ Returns the typehint associated with the parameter */
+ZEND_METHOD(reflection_parameter, getTypehintText)
+{
+ reflection_object *intern;
+ parameter_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:
+ RETURN_EMPTY_STRING();
+ }
+}
+/* }}} */
+
/* {{{ proto public bool ReflectionParameter::isArray()
Returns whether parameter MUST be an array */
ZEND_METHOD(reflection_parameter, isArray)
@@ -6026,6 +6068,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, isArray, arginfo_reflection__void, 0)
ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0)
ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0)
diff --git a/ext/reflection/tests/parameters_typehint.phpt
b/ext/reflection/tests/parameters_typehint.phpt
new file mode 100644
index 0000000...04aaeed
--- /dev/null
+++ b/ext/reflection/tests/parameters_typehint.phpt
@@ -0,0 +1,25 @@
+--TEST--
+ReflectionParameter::hasTypehint() / getTypehintText()
+--FILE--
+<?php
+function foo(stdClass $a, array $b, callable $c, $d) { }
+
+$rf = new ReflectionFunction('foo');
+foreach ($rf->getParameters() as $idx => $rp) {
+ echo "** Parameter $idx\n";
+ var_dump($rp->hasTypehint());
+ var_dump($rp->getTypehintText());
+}
+--EXPECT--
+** Parameter 0
+bool(true)
+string(8) "stdClass"
+** Parameter 1
+bool(true)
+string(5) "array"
+** Parameter 2
+bool(true)
+string(8) "callable"
+** Parameter 3
+bool(false)
+string(0) ""