summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-09-04 14:23:43 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-09-04 14:32:34 +0200
commit8107a1da5af480839b226882e5c27fd76b191ee1 (patch)
tree07513d5929667e627b0fd23adffd005940ebf87c /ext/reflection
parente50449bcb4c72f13577aecc195baf691a8341a29 (diff)
downloadphp-git-8107a1da5af480839b226882e5c27fd76b191ee1.tar.gz
Use ZPP instead of custom type checks
We can add these types as a native type declaration to stubs as a side-effect. Closes GH-6068
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c23
-rw-r--r--ext/reflection/php_reflection.stub.php3
-rw-r--r--ext/reflection/php_reflection_arginfo.h4
-rw-r--r--ext/reflection/tests/ReflectionClass_constructor_002.phpt8
-rw-r--r--ext/reflection/tests/ReflectionClass_toString_001.phpt2
5 files changed, 17 insertions, 23 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 11b834503b..3b7c29b087 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -3684,38 +3684,35 @@ ZEND_METHOD(ReflectionClassConstant, getAttributes)
/* {{{ reflection_class_object_ctor */
static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_object)
{
- zval *argument;
zval *object;
+ zend_string *arg_class = NULL;
+ zend_object *arg_obj;
reflection_object *intern;
zend_class_entry *ce;
if (is_object) {
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_OBJECT(argument)
+ Z_PARAM_OBJ(arg_obj)
ZEND_PARSE_PARAMETERS_END();
} else {
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(argument)
+ Z_PARAM_STR_OR_OBJ(arg_class, arg_obj)
ZEND_PARSE_PARAMETERS_END();
}
object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
- if (Z_TYPE_P(argument) == IS_OBJECT) {
- ZVAL_STR_COPY(reflection_prop_name(object), Z_OBJCE_P(argument)->name);
- intern->ptr = Z_OBJCE_P(argument);
+ if (arg_obj) {
+ ZVAL_STR_COPY(reflection_prop_name(object), arg_obj->ce->name);
+ intern->ptr = arg_obj->ce;
if (is_object) {
- ZVAL_COPY(&intern->obj, argument);
+ ZVAL_OBJ_COPY(&intern->obj, arg_obj);
}
} else {
- if (!try_convert_to_string(argument)) {
- RETURN_THROWS();
- }
-
- if ((ce = zend_lookup_class(Z_STR_P(argument))) == NULL) {
+ if ((ce = zend_lookup_class(arg_class)) == NULL) {
if (!EG(exception)) {
- zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", Z_STRVAL_P(argument));
+ zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", ZSTR_VAL(arg_class));
}
RETURN_THROWS();
}
diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php
index 539520597f..311e748e9b 100644
--- a/ext/reflection/php_reflection.stub.php
+++ b/ext/reflection/php_reflection.stub.php
@@ -202,8 +202,7 @@ class ReflectionClass implements Reflector
{
final private function __clone() {}
- /** @param object|string $objectOrClass */
- public function __construct($objectOrClass) {}
+ public function __construct(object|string $objectOrClass) {}
public function __toString(): string {}
diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h
index 00013c7a50..c0ff2d75e2 100644
--- a/ext/reflection/php_reflection_arginfo.h
+++ b/ext/reflection/php_reflection_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: beaf79270ab56d2e87a301a4a5d4444b2cc520d8 */
+ * Stub hash: 1311fc5c498d6f16afb5a18aee2d60e72048174f */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -150,7 +150,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass___clone arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass___construct, 0, 0, 1)
- ZEND_ARG_INFO(0, objectOrClass)
+ ZEND_ARG_TYPE_MASK(0, objectOrClass, MAY_BE_OBJECT|MAY_BE_STRING, NULL)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass___toString arginfo_class_ReflectionFunction___toString
diff --git a/ext/reflection/tests/ReflectionClass_constructor_002.phpt b/ext/reflection/tests/ReflectionClass_constructor_002.phpt
index 54f4b8eda2..44ff37a962 100644
--- a/ext/reflection/tests/ReflectionClass_constructor_002.phpt
+++ b/ext/reflection/tests/ReflectionClass_constructor_002.phpt
@@ -28,7 +28,7 @@ try {
try {
var_dump(new ReflectionClass(array(1,2,3)));
-} catch (Exception $e) {
+} catch (TypeError $e) {
echo $e->getMessage() . "\n";
}
@@ -45,13 +45,11 @@ try {
}
?>
---EXPECTF--
+--EXPECT--
ReflectionClass::__construct() expects exactly 1 parameter, 0 given
Class "" does not exist
Class "1" does not exist
Class "1" does not exist
-
-Warning: Array to string conversion in %s on line %d
-Class "Array" does not exist
+ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, array given
ReflectionClass::__construct() expects exactly 1 parameter, 2 given
Class "X" does not exist
diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt
index bb9ead8ce3..00e41bfcc9 100644
--- a/ext/reflection/tests/ReflectionClass_toString_001.phpt
+++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt
@@ -37,7 +37,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
Method [ <internal:Reflection, ctor> public method __construct ] {
- Parameters [1] {
- Parameter #0 [ <required> $objectOrClass ]
+ Parameter #0 [ <required> object|string $objectOrClass ]
}
}