Skip to content

Added ReflectionProperty::getClassName() #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,34 @@ ZEND_METHOD(reflection_parameter, getClass)
}
/* }}} */

/* {{{ proto public string ReflectionParameter::getClassName()
Returns this parameters's class name or null if this there is none */
ZEND_METHOD(reflection_parameter, getClassName)
{
reflection_object *intern;
parameter_reference *param;

if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(param);

if (param->arg_info->class_name) {
const char *class_name;
size_t class_name_len;

if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
class_name = ((zend_internal_arg_info*)param->arg_info)->class_name;
class_name_len = strlen(class_name);

RETURN_STRINGL(class_name, class_name_len);
} else {
ZVAL_STR_COPY(return_value, param->arg_info->class_name);
}
}
}
/* }}} */

/* {{{ proto public bool ReflectionParameter::isArray()
Returns whether parameter MUST be an array */
ZEND_METHOD(reflection_parameter, isArray)
Expand Down Expand Up @@ -6075,6 +6103,7 @@ 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, getClassName, 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)
Expand Down
34 changes: 34 additions & 0 deletions ext/reflection/tests/ReflectionParameter_getClassName.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Test ReflectionParameter::getClassName() usage.
--FILE--
<?php

use Bar\Baz;

class Foo {
public function bar(Qux $qux, $bar, Baz $baz, \Bar\Quz $quz) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this alsy contain array and callable typehtint?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Just classes.

I'll sort this all the morning. It's 4am here in NY.

Sent from my iPhone

On Jan 31, 2015, at 3:41 AM, Markus Staab [email protected] wrote:

In ext/reflection/tests/ReflectionParameter_getClassName.phpt:

@@ -0,0 +1,25 @@
+--TEST--
+Test ReflectionParameter::getClassName() usage.
+--FILE--
+<?php
+
+use Bar\Baz;
+
+class Foo {

  • public function bar(Qux $qux, $bar, Baz $baz, \Bar\Quz $quz) {}
    Should this alsy contain array and callable typehtint?


Reply to this email directly or view it on GitHub.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the sake of completeness it might be a good idea to add params with array and callable typehints in the test case even though they aren't strictly needed for this patch's functionality. This would help ensure consistent behavior going forward (e.g. if someone gets a wild hair to change how the "pseudo" hints are implemented you don't want this functionality to break).


public function waldo(array $wibble, callable $wobble) {}
}

$class = new ReflectionClass(Foo::class);
$method = $class->getMethod("bar");
$params = $method->getParameters();
var_dump($params[0]->getClassName());
var_dump($params[1]->getClassName());
var_dump($params[2]->getClassName());
var_dump($params[3]->getClassName());

$method = $class->getMethod("waldo");
$params = $method->getParameters();
var_dump($params[0]->getClassName());
var_dump($params[1]->getClassName());


--EXPECT--
string(3) "Qux"
NULL
string(7) "Bar\Baz"
string(7) "Bar\Quz"
NULL
NULL