Skip to content

Commit f84a329

Browse files
author
Phil Sturgeon
committed
Added ReflectionProperty::getClassName()
1 parent 130d732 commit f84a329

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,37 @@ ZEND_METHOD(reflection_parameter, getClass)
24882488
}
24892489
/* }}} */
24902490

2491+
/* {{{ proto public string ReflectionParameter::getClassName()
2492+
Returns this parameters's class name or null if this there is none */
2493+
ZEND_METHOD(reflection_parameter, getClassName)
2494+
{
2495+
reflection_object *intern;
2496+
parameter_reference *param;
2497+
2498+
if (zend_parse_parameters_none() == FAILURE) {
2499+
return;
2500+
}
2501+
GET_REFLECTION_OBJECT_PTR(param);
2502+
2503+
if (param->arg_info->class_name) {
2504+
const char *class_name;
2505+
size_t class_name_len;
2506+
2507+
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
2508+
class_name = ((zend_internal_arg_info*)param->arg_info)->class_name;
2509+
class_name_len = strlen(class_name);
2510+
2511+
RETURN_STRINGL(class_name, class_name_len);
2512+
} else {
2513+
class_name = param->arg_info->class_name->val;
2514+
class_name_len = param->arg_info->class_name->len;
2515+
2516+
RETURN_STR(param->arg_info->class_name);
2517+
}
2518+
}
2519+
}
2520+
/* }}} */
2521+
24912522
/* {{{ proto public bool ReflectionParameter::isArray()
24922523
Returns whether parameter MUST be an array */
24932524
ZEND_METHOD(reflection_parameter, isArray)
@@ -6075,6 +6106,7 @@ static const zend_function_entry reflection_parameter_functions[] = {
60756106
ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0)
60766107
ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0)
60776108
ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0)
6109+
ZEND_ME(reflection_parameter, getClassName, arginfo_reflection__void, 0)
60786110
ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0)
60796111
ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0)
60806112
ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Test ReflectionProperty::getClassName() usage.
3+
--FILE--
4+
<?php
5+
class Foo {
6+
public function bar(Qux $qux) {}
7+
}
8+
9+
$class = new ReflectionClass(Foo::class);
10+
$method = $class->getMethod("bar");
11+
$params = $method->getParameters();
12+
var_dump($params[0]->getClassName());
13+
14+
--EXPECT--
15+
string(3) "Qux"

0 commit comments

Comments
 (0)