Cleanup argument handling in ext/reflection

Closes GH-5850
This commit is contained in:
Máté Kocsis committed 2020-07-24 17:47:42 +02:00
1 parent 1f8a93abaa
commit 8664ff7ae1
15 files changed
+208 -252

No files matched your search

+2 -2
View File
@@ -394,9 +394,9 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* {
}
/* }}} */
ZEND_API const zend_function *zend_get_closure_method_def(zval *obj) /* {{{ */
ZEND_API const zend_function *zend_get_closure_method_def(zend_object *obj) /* {{{ */
{
zend_closure *closure = (zend_closure *)Z_OBJ_P(obj);
zend_closure *closure = (zend_closure *) obj;
return &closure->func;
}
/* }}} */
+1 -1
View File
@@ -35,7 +35,7 @@ extern ZEND_API zend_class_entry *zend_ce_closure;
ZEND_API void zend_create_closure(zval *res, zend_function *op_array, zend_class_entry *scope, zend_class_entry *called_scope, zval *this_ptr);
ZEND_API void zend_create_fake_closure(zval *res, zend_function *op_array, zend_class_entry *scope, zend_class_entry *called_scope, zval *this_ptr);
ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *obj);
ZEND_API const zend_function *zend_get_closure_method_def(zval *obj);
ZEND_API const zend_function *zend_get_closure_method_def(zend_object *obj);
ZEND_API zval* zend_get_closure_this_ptr(zval *obj);
END_EXTERN_C()
+87 -120
View File
@@ -1480,7 +1480,7 @@ ZEND_METHOD(Reflection, getModifierNames)
ZEND_METHOD(ReflectionFunction, __construct)
{
zval *object;
zval *closure = NULL;
zend_object *closure_obj = NULL;
reflection_object *intern;
zend_function *fptr;
zend_string *fname, *lcname;
@@ -1488,17 +1488,16 @@ ZEND_METHOD(ReflectionFunction, __construct)
object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) {
fptr = (zend_function*)zend_get_closure_method_def(closure);
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR_OR_OBJ_OF_CLASS(fname, closure_obj, zend_ce_closure)
ZEND_PARSE_PARAMETERS_END();
if (closure_obj) {
fptr = (zend_function*)zend_get_closure_method_def(closure_obj);
} else {
ALLOCA_FLAG(use_heap)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &fname) == FAILURE) {
RETURN_THROWS();
}
if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) {
/* Ignore leading "\" */
ALLOCA_FLAG(use_heap)
ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1);
fptr = zend_fetch_function(lcname);
@@ -1519,8 +1518,8 @@ ZEND_METHOD(ReflectionFunction, __construct)
ZVAL_STR_COPY(reflection_prop_name(object), fptr->common.function_name);
intern->ptr = fptr;
intern->ref_type = REF_TYPE_FUNCTION;
if (closure) {
ZVAL_OBJ_COPY(&intern->obj, Z_OBJ_P(closure));
if (closure_obj) {
ZVAL_OBJ_COPY(&intern->obj, closure_obj);
} else {
ZVAL_UNDEF(&intern->obj);
}
@@ -1603,7 +1602,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureScopeClass)
}
GET_REFLECTION_OBJECT();
if (!Z_ISUNDEF(intern->obj)) {
closure_func = zend_get_closure_method_def(&intern->obj);
closure_func = zend_get_closure_method_def(Z_OBJ(intern->obj));
if (closure_func && closure_func->common.scope) {
zend_reflection_class_factory(closure_func->common.scope, return_value);
}
@@ -2315,7 +2314,7 @@ ZEND_METHOD(ReflectionParameter, __construct)
ce = Z_OBJCE_P(reference);
if (instanceof_function(ce, zend_ce_closure)) {
fptr = (zend_function *)zend_get_closure_method_def(reference);
fptr = (zend_function *)zend_get_closure_method_def(Z_OBJ_P(reference));
Z_ADDREF_P(reference);
is_closure = 1;
} else if ((fptr = zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) == NULL) {
@@ -3017,7 +3016,6 @@ ZEND_METHOD(ReflectionMethod, __construct)
object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
/* Find the class entry */
switch (Z_TYPE_P(classname)) {
case IS_STRING:
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
@@ -3519,38 +3517,31 @@ ZEND_METHOD(ReflectionMethod, setAccessible)
/* {{{ Constructor. Throws an Exception in case the given class constant does not exist */
ZEND_METHOD(ReflectionClassConstant, __construct)
{
zval *classname, *object;
zval *object;
zend_string *classname_str;
zend_object *classname_obj;
zend_string *constname;
reflection_object *intern;
zend_class_entry *ce;
zend_class_constant *constant = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &classname, &constname) == FAILURE) {
RETURN_THROWS();
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR_OR_OBJ(classname_str, classname_obj)
Z_PARAM_STR(constname)
ZEND_PARSE_PARAMETERS_END();
if (classname_obj) {
ce = classname_obj->ce;
} else {
if ((ce = zend_lookup_class(classname_str)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str));
RETURN_THROWS();
}
}
object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
/* Find the class entry */
switch (Z_TYPE_P(classname)) {
case IS_STRING:
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Class \"%s\" does not exist", Z_STRVAL_P(classname));
RETURN_THROWS();
}
break;
case IS_OBJECT:
ce = Z_OBJCE_P(classname);
break;
default:
zend_argument_error(reflection_exception_ptr, 1, "must be of type object|string, %s given", zend_zval_type_name(classname));
RETURN_THROWS();
}
if ((constant = zend_hash_find_ptr(&ce->constants_table, constname)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Constant %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(constname));
RETURN_THROWS();
@@ -3814,7 +3805,7 @@ ZEND_METHOD(ReflectionClass, getStaticProperties)
GET_REFLECTION_OBJECT_PTR(ce);
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
RETURN_THROWS();
}
if (ce->default_static_members_count && !CE_STATIC_MEMBERS(ce)) {
@@ -3863,7 +3854,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
GET_REFLECTION_OBJECT_PTR(ce);
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
RETURN_THROWS();
}
old_scope = EG(fake_scope);
@@ -3901,7 +3892,7 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue)
GET_REFLECTION_OBJECT_PTR(ce);
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
RETURN_THROWS();
}
old_scope = EG(fake_scope);
EG(fake_scope) = ce;
@@ -3945,7 +3936,7 @@ ZEND_METHOD(ReflectionClass, getDefaultProperties)
GET_REFLECTION_OBJECT_PTR(ce);
array_init(return_value);
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
RETURN_THROWS();
}
add_class_vars(ce, 1, return_value);
add_class_vars(ce, 0, return_value);
@@ -4967,38 +4958,30 @@ ZEND_METHOD(ReflectionClass, isSubclassOf)
{
reflection_object *intern, *argument;
zend_class_entry *ce, *class_ce;
zval *class_name;
zend_string *class_str;
zend_object *class_obj;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR_OR_OBJ_OF_CLASS(class_str, class_obj, reflection_class_ptr)
ZEND_PARSE_PARAMETERS_END();
if (class_obj) {
argument = reflection_object_from_obj(class_obj);
if (argument->ptr == NULL) {
zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
RETURN_THROWS();
}
class_ce = argument->ptr;
} else {
if ((class_ce = zend_lookup_class(class_str)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(class_str));
RETURN_THROWS();
}
}
GET_REFLECTION_OBJECT_PTR(ce);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &class_name) == FAILURE) {
RETURN_THROWS();
}
switch (Z_TYPE_P(class_name)) {
case IS_STRING:
if ((class_ce = zend_lookup_class(Z_STR_P(class_name))) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Class \"%s\" does not exist", Z_STRVAL_P(class_name));
RETURN_THROWS();
}
break;
case IS_OBJECT:
if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr)) {
argument = Z_REFLECTION_P(class_name);
if (argument->ptr == NULL) {
zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
RETURN_THROWS();
}
class_ce = argument->ptr;
break;
}
/* no break */
default:
zend_argument_error(reflection_exception_ptr, 1, "must be of type ReflectionClass|string, %s given", zend_zval_type_name(class_name));
RETURN_THROWS();
}
RETURN_BOOL((ce != class_ce && instanceof_function(ce, class_ce)));
}
/* }}} */
@@ -5007,44 +4990,36 @@ ZEND_METHOD(ReflectionClass, isSubclassOf)
ZEND_METHOD(ReflectionClass, implementsInterface)
{
reflection_object *intern, *argument;
zend_string *interface_str;
zend_class_entry *ce, *interface_ce;
zval *interface;
zend_object *interface_obj;
GET_REFLECTION_OBJECT_PTR(ce);
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR_OR_OBJ_OF_CLASS(interface_str, interface_obj, reflection_class_ptr)
ZEND_PARSE_PARAMETERS_END();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &interface) == FAILURE) {
RETURN_THROWS();
}
switch (Z_TYPE_P(interface)) {
case IS_STRING:
if ((interface_ce = zend_lookup_class(Z_STR_P(interface))) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Interface \"%s\" does not exist", Z_STRVAL_P(interface));
RETURN_THROWS();
}
break;
case IS_OBJECT:
if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr)) {
argument = Z_REFLECTION_P(interface);
if (argument->ptr == NULL) {
zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
RETURN_THROWS();
}
interface_ce = argument->ptr;
break;
}
/* no break */
default:
zend_argument_error(reflection_exception_ptr, 1, "must be of type ReflectionClass|string, %s given", zend_zval_type_name(interface));
if (interface_obj) {
argument = reflection_object_from_obj(interface_obj);
if (argument->ptr == NULL) {
zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
RETURN_THROWS();
}
interface_ce = argument->ptr;
} else {
if ((interface_ce = zend_lookup_class(interface_str)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Interface \"%s\" does not exist", ZSTR_VAL(interface_str));
RETURN_THROWS();
}
}
if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"%s is not an interface", ZSTR_VAL(interface_ce->name));
zend_throw_exception_ex(reflection_exception_ptr, 0, "%s is not an interface", ZSTR_VAL(interface_ce->name));
RETURN_THROWS();
}
GET_REFLECTION_OBJECT_PTR(ce);
RETURN_BOOL(instanceof_function(ce, interface_ce));
}
/* }}} */
@@ -5178,7 +5153,8 @@ ZEND_METHOD(ReflectionObject, __construct)
/* {{{ Constructor. Throws an Exception in case the given property does not exist */
ZEND_METHOD(ReflectionProperty, __construct)
{
zval *classname;
zend_string *classname_str;
zend_object *classname_obj;
zend_string *name;
int dynam_prop = 0;
zval *object;
@@ -5187,30 +5163,21 @@ ZEND_METHOD(ReflectionProperty, __construct)
zend_property_info *property_info = NULL;
property_reference *reference;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &classname, &name) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR_OR_OBJ(classname_str, classname_obj)
Z_PARAM_STR(name)
ZEND_PARSE_PARAMETERS_END();
object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
/* Find the class entry */
switch (Z_TYPE_P(classname)) {
case IS_STRING:
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Class \"%s\" does not exist", Z_STRVAL_P(classname));
RETURN_THROWS();
}
break;
case IS_OBJECT:
ce = Z_OBJCE_P(classname);
break;
default:
zend_argument_error(reflection_exception_ptr, 1, "must be of type object|string, %s given", zend_zval_type_name(classname));
if (classname_obj) {
ce = classname_obj->ce;
} else {
if ((ce = zend_lookup_class(classname_str)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str));
RETURN_THROWS();
}
}
property_info = zend_hash_find_ptr(&ce->properties_info, name);
@@ -5218,8 +5185,8 @@ ZEND_METHOD(ReflectionProperty, __construct)
|| ((property_info->flags & ZEND_ACC_PRIVATE)
&& property_info->ce != ce)) {
/* Check for dynamic properties */
if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT) {
if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(Z_OBJ_P(classname)), name)) {
if (property_info == NULL && classname_obj) {
if (zend_hash_exists(classname_obj->handlers->get_properties(classname_obj), name)) {
dynam_prop = 1;
}
}
+16 -27
View File
@@ -102,8 +102,7 @@ abstract class ReflectionFunctionAbstract implements Reflector
class ReflectionFunction extends ReflectionFunctionAbstract
{
/** @param string|Closure $name */
public function __construct($name) {}
public function __construct(Closure|string $function) {}
public function __toString(): string {}
@@ -148,8 +147,8 @@ final class ReflectionGenerator
class ReflectionMethod extends ReflectionFunctionAbstract
{
/** @param object|string $class_or_method */
public function __construct($class_or_method, string $name = UNKNOWN) {}
/** @param object|string $objectOrMethod */
public function __construct($objectOrMethod, string $method = UNKNOWN) {}
public function __toString(): string {}
@@ -196,15 +195,15 @@ class ReflectionMethod extends ReflectionFunctionAbstract
public function getPrototype() {}
/** @return void */
public function setAccessible(bool $visible) {}
public function setAccessible(bool $isAccessible) {}
}
class ReflectionClass implements Reflector
{
final private function __clone() {}
/** @param object|string $argument */
public function __construct($argument) {}
/** @param object|string $objectOrClass */
public function __construct($objectOrClass) {}
public function __toString(): string {}
@@ -308,7 +307,7 @@ class ReflectionClass implements Reflector
public function isInstance(object $object) {}
/** @return object */
public function newInstance(...$args) {}
public function newInstance(mixed ...$args) {}
/** @return object */
public function newInstanceWithoutConstructor() {}
@@ -319,11 +318,8 @@ class ReflectionClass implements Reflector
/** @return ReflectionClass|false */
public function getParentClass() {}
/**
* @param string|ReflectionClass $class
* @return bool
*/
public function isSubclassOf($class) {}
/** @return bool */
public function isSubclassOf(ReflectionClass|string $class) {}
/** @return array|null */
public function getStaticProperties() {}
@@ -346,11 +342,8 @@ class ReflectionClass implements Reflector
*/
public function isIterateable() {}
/**
* @param string|ReflectionClass $interface
* @return bool
*/
public function implementsInterface($interface) {}
/** @return bool */
public function implementsInterface(ReflectionClass|string $interface) {}
/** @return ReflectionExtension|null */
public function getExtension() {}
@@ -381,8 +374,7 @@ class ReflectionProperty implements Reflector
/** @alias ReflectionClass::__clone */
final private function __clone() {}
/** @param string|object $class */
public function __construct($class, string $name) {}
public function __construct(object|string $class, string $property) {}
public function __toString(): string {}
@@ -393,7 +385,7 @@ class ReflectionProperty implements Reflector
public function getValue(?object $object = null) {}
/** @return void */
public function setValue($object_or_value, $value = UNKNOWN) {}
public function setValue($objectOrValue, $value = UNKNOWN) {}
/** @return bool */
public function isInitialized(?object $object = null) {}
@@ -425,7 +417,7 @@ class ReflectionProperty implements Reflector
public function getDocComment() {}
/** @return void */
public function setAccessible(bool $visible) {}
public function setAccessible(bool $isAccessible) {}
/** @return ReflectionType|null */
public function getType() {}
@@ -447,8 +439,7 @@ class ReflectionClassConstant implements Reflector
/** @alias ReflectionClass::__clone */
final private function __clone() {}
/** @return string|object */
public function __construct($class, string $name) {}
public function __construct(object|string $class, string $constant) {}
public function __toString(): string {}
@@ -485,9 +476,7 @@ class ReflectionParameter implements Reflector
/** @alias ReflectionClass::__clone */
final private function __clone() {}
/**
* @param $function string|array|object
*/
/** @param string|array|object $function */
public function __construct($function, int|string $parameter) {}
public function __toString(): string {}
+16 -15
View File
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 330900e4fdcc9691ef971a270d065f859cee47bd */
* Stub hash: 0a3d9fb707ddf5e508075799bf06ff42b849a4b8 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -64,7 +64,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFunctionAbstract
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionFunction___construct, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_OBJ_TYPE_MASK(0, function, Closure, MAY_BE_STRING, NULL)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFunction___toString, 0, 0, IS_STRING, 0)
@@ -101,8 +101,8 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionGenerator_getExecutingGenerator arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod___construct, 0, 0, 1)
ZEND_ARG_INFO(0, class_or_method)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_ARG_INFO(0, objectOrMethod)
ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionMethod___toString arginfo_class_ReflectionFunction___toString
@@ -144,13 +144,13 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionMethod_getPrototype arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_setAccessible, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, visible, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, isAccessible, _IS_BOOL, 0)
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, argument)
ZEND_ARG_INFO(0, objectOrClass)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass___toString arginfo_class_ReflectionFunction___toString
@@ -229,9 +229,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_isInstance, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_newInstance, 0, 0, 0)
ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass_newInstance arginfo_class_ReflectionFunction_invoke
#define arginfo_class_ReflectionClass_newInstanceWithoutConstructor arginfo_class_ReflectionFunctionAbstract___clone
@@ -242,7 +240,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass_getParentClass arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_isSubclassOf, 0, 0, 1)
ZEND_ARG_INFO(0, class)
ZEND_ARG_OBJ_TYPE_MASK(0, class, ReflectionClass, MAY_BE_STRING, NULL)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass_getStaticProperties arginfo_class_ReflectionFunctionAbstract___clone
@@ -264,7 +262,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass_isIterateable arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_implementsInterface, 0, 0, 1)
ZEND_ARG_INFO(0, interface)
ZEND_ARG_OBJ_TYPE_MASK(0, interface, ReflectionClass, MAY_BE_STRING, NULL)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClass_getExtension arginfo_class_ReflectionFunctionAbstract___clone
@@ -286,8 +284,8 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionProperty___clone arginfo_class_ReflectionFunctionAbstract___clone
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionProperty___construct, 0, 0, 2)
ZEND_ARG_INFO(0, class)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_ARG_TYPE_MASK(0, class, MAY_BE_OBJECT|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO(0, property, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionProperty___toString arginfo_class_ReflectionFunction___toString
@@ -299,7 +297,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionProperty_getValue, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionProperty_setValue, 0, 0, 1)
ZEND_ARG_INFO(0, object_or_value)
ZEND_ARG_INFO(0, objectOrValue)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
@@ -338,7 +336,10 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClassConstant___clone arginfo_class_ReflectionFunctionAbstract___clone
#define arginfo_class_ReflectionClassConstant___construct arginfo_class_ReflectionProperty___construct
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClassConstant___construct, 0, 0, 2)
ZEND_ARG_TYPE_MASK(0, class, MAY_BE_OBJECT|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO(0, constant, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionClassConstant___toString arginfo_class_ReflectionFunction___toString
+3 -3
View File
@@ -27,13 +27,13 @@ foreach ($a as $key=>$val) {
echo "Done\n";
?>
--EXPECT--
string(91) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name"
string(91) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name"
string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name"
string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name"
string(23) "Class "" does not exist"
string(24) "Class "a" does not exist"
string(23) "Class "" does not exist"
string(24) "Class "a" does not exist"
string(23) "Class "" does not exist"
string(104) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, int given"
string(103) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be of type object|string, int given"
string(23) "Class "" does not exist"
Done
@@ -20,17 +20,17 @@ foreach ($classNames as $className) {
foreach ($rcs as $childName => $child) {
foreach ($rcs as $parentName => $parent) {
echo "Does " . $childName . " implement " . $parentName . "? \n";
echo "Does " . $childName . " implement " . $parentName . "?\n";
echo " - Using object argument: ";
try {
var_dump($child->implementsInterface($parent));
} catch (Exception $e) {
} catch (Exception|TypeError $e) {
echo $e->getMessage() . "\n";
}
echo " - Using string argument: ";
try {
var_dump($child->implementsInterface($parentName));
} catch (Exception $e) {
} catch (Exception|TypeError $e) {
echo $e->getMessage() . "\n";
}
}
@@ -40,105 +40,105 @@ foreach ($rcs as $childName => $child) {
echo "\n\nTest bad arguments:\n";
try {
var_dump($rcs['A']->implementsInterface());
} catch (TypeError $e) {
$rcs['A']->implementsInterface();
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rcs['A']->implementsInterface('C', 'C'));
} catch (TypeError $e) {
$rcs['A']->implementsInterface('C', 'C');
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rcs['A']->implementsInterface(null));
} catch (Exception $e) {
$rcs['A']->implementsInterface(null);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rcs['A']->implementsInterface('ThisClassDoesNotExist'));
} catch (Exception $e) {
$rcs['A']->implementsInterface('ThisClassDoesNotExist');
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rcs['A']->implementsInterface(2));
} catch (Exception $e) {
$rcs['A']->implementsInterface(2);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
Does A implement A?
Does A implement A?
- Using object argument: A is not an interface
- Using string argument: A is not an interface
Does A implement B?
Does A implement B?
- Using object argument: B is not an interface
- Using string argument: B is not an interface
Does A implement C?
Does A implement C?
- Using object argument: C is not an interface
- Using string argument: C is not an interface
Does A implement I1?
Does A implement I1?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does A implement I2?
Does A implement I2?
- Using object argument: bool(false)
- Using string argument: bool(false)
Does B implement A?
Does B implement A?
- Using object argument: A is not an interface
- Using string argument: A is not an interface
Does B implement B?
Does B implement B?
- Using object argument: B is not an interface
- Using string argument: B is not an interface
Does B implement C?
Does B implement C?
- Using object argument: C is not an interface
- Using string argument: C is not an interface
Does B implement I1?
Does B implement I1?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does B implement I2?
Does B implement I2?
- Using object argument: bool(false)
- Using string argument: bool(false)
Does C implement A?
Does C implement A?
- Using object argument: A is not an interface
- Using string argument: A is not an interface
Does C implement B?
Does C implement B?
- Using object argument: B is not an interface
- Using string argument: B is not an interface
Does C implement C?
Does C implement C?
- Using object argument: C is not an interface
- Using string argument: C is not an interface
Does C implement I1?
Does C implement I1?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does C implement I2?
Does C implement I2?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does I1 implement A?
Does I1 implement A?
- Using object argument: A is not an interface
- Using string argument: A is not an interface
Does I1 implement B?
Does I1 implement B?
- Using object argument: B is not an interface
- Using string argument: B is not an interface
Does I1 implement C?
Does I1 implement C?
- Using object argument: C is not an interface
- Using string argument: C is not an interface
Does I1 implement I1?
Does I1 implement I1?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does I1 implement I2?
Does I1 implement I2?
- Using object argument: bool(false)
- Using string argument: bool(false)
Does I2 implement A?
Does I2 implement A?
- Using object argument: A is not an interface
- Using string argument: A is not an interface
Does I2 implement B?
Does I2 implement B?
- Using object argument: B is not an interface
- Using string argument: B is not an interface
Does I2 implement C?
Does I2 implement C?
- Using object argument: C is not an interface
- Using string argument: C is not an interface
Does I2 implement I1?
Does I2 implement I1?
- Using object argument: bool(true)
- Using string argument: bool(true)
Does I2 implement I2?
Does I2 implement I2?
- Using object argument: bool(true)
- Using string argument: bool(true)
@@ -146,6 +146,6 @@ Does I2 implement I2?
Test bad arguments:
ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given
ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given
ReflectionClass::implementsInterface(): Argument #1 ($interface) must be of type ReflectionClass|string, null given
Interface "" does not exist
Interface "ThisClassDoesNotExist" does not exist
ReflectionClass::implementsInterface(): Argument #1 ($interface) must be of type ReflectionClass|string, int given
Interface "2" does not exist
@@ -10,28 +10,28 @@ $rc = new ReflectionClass('A');
echo "\n\nTest bad arguments:\n";
try {
var_dump($rc->isSubclassOf());
} catch (TypeError $e) {
$rc->isSubclassOf();
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rc->isSubclassOf('C', 'C'));
} catch (TypeError $e) {
$rc->isSubclassOf('C', 'C');
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rc->isSubclassOf(null));
} catch (Exception $e) {
$rc->isSubclassOf(null);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rc->isSubclassOf('ThisClassDoesNotExist'));
} catch (Exception $e) {
$rc->isSubclassOf('ThisClassDoesNotExist');
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($rc->isSubclassOf(2));
} catch (Exception $e) {
$rc->isSubclassOf(2);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
?>
@@ -39,6 +39,6 @@ try {
Test bad arguments:
ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given
ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given
ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, null given
Class "" does not exist
Class "ThisClassDoesNotExist" does not exist
ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, int given
Class "2" does not exist
@@ -37,7 +37,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
Method [ <internal:Reflection, ctor> public method __construct ] {
- Parameters [1] {
Parameter #0 [ <required> $argument ]
Parameter #0 [ <required> $objectOrClass ]
}
}
@@ -261,7 +261,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
Method [ <internal:Reflection> public method newInstance ] {
- Parameters [1] {
Parameter #0 [ <optional> ...$args = <default> ]
Parameter #0 [ <optional> mixed ...$args = <default> ]
}
}
@@ -287,7 +287,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
Method [ <internal:Reflection> public method isSubclassOf ] {
- Parameters [1] {
Parameter #0 [ <required> $class ]
Parameter #0 [ <required> ReflectionClass|string $class ]
}
}
@@ -334,7 +334,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
Method [ <internal:Reflection> public method implementsInterface ] {
- Parameters [1] {
Parameter #0 [ <required> $interface ]
Parameter #0 [ <required> ReflectionClass|string $interface ]
}
}
@@ -35,8 +35,8 @@ try {
?>
--EXPECT--
Ok - ReflectionFunction::__construct(): Argument #1 ($name) must be of type string, array given
Ok - ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given
Function nonExistentFunction() does not exist
Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given
Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given
Ok - ReflectionFunction::__construct(): Argument #1 ($name) must be of type string, array given
Ok - ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given
@@ -115,8 +115,8 @@ __toString():
string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
- Parameters [2] {
Parameter #0 [ <required> $class ]
Parameter #1 [ <required> string $name ]
Parameter #0 [ <required> object|string $class ]
Parameter #1 [ <required> string $property ]
}
}
"
@@ -65,17 +65,17 @@ try {
?>
--EXPECTF--
Wrong type of argument (bool):
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
Stack trace:
#0 %s ReflectionMethod->__construct('1')
#1 {main}
Wrong type of argument (int):
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
Stack trace:
#0 %s ReflectionMethod->__construct('3')
#1 {main}
Wrong type of argument (bool, string):
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, bool given in %s:%d
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be of type object|string, bool given in %s:%d
Stack trace:
#0 %s ReflectionMethod->__construct(true, 'foo')
#1 {main}
@@ -85,7 +85,7 @@ Stack trace:
#0 %s ReflectionMethod->__construct('TestClass', '1')
#1 {main}
No method given:
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
Stack trace:
#0 %s ReflectionMethod->__construct('TestClass')
#1 {main}
@@ -57,5 +57,5 @@ Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Too many arguments:
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Ok - Class "InvalidClassName" does not exist
Ok - ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, array given
Ok - ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be of type object|string, array given
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given
@@ -10,28 +10,28 @@ $ro = new ReflectionObject(new C);
echo "\n\nTest bad arguments:\n";
try {
var_dump($ro->isSubclassOf());
} catch (TypeError $e) {
$ro->isSubclassOf();
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf('C', 'C'));
} catch (TypeError $e) {
$ro->isSubclassOf('C', 'C');
} catch (ArgumentCountError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf(null));
} catch (Exception $e) {
$ro->isSubclassOf(null);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf('ThisClassDoesNotExist'));
} catch (Exception $e) {
$ro->isSubclassOf('ThisClassDoesNotExist');
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf(2));
} catch (Exception $e) {
$ro->isSubclassOf(2);
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
?>
@@ -39,6 +39,6 @@ try {
Test bad arguments:
ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given
ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given
ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, null given
Class "" does not exist
Class "ThisClassDoesNotExist" does not exist
ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, int given
Class "2" does not exist
@@ -10,15 +10,14 @@ $a = 5;
echo "Non-existent class:\n";
try {
$propInfo = new ReflectionProperty("NonExistentClass", "prop");
}
catch(Exception $e) {
new ReflectionProperty("NonExistentClass", "prop");
} catch (ReflectionException $e) {
echo $e->getMessage();
}
echo "\n\nWrong property parameter type:\n";
try {
$propInfo = new ReflectionProperty($a, 'TestClass');
new ReflectionProperty($a, 'TestClass');
}
catch(ReflectionException $e) {
echo $e->getMessage();
@@ -26,9 +25,9 @@ catch(ReflectionException $e) {
echo "\n\nNon-existent property:\n";
try {
$propInfo = new ReflectionProperty('TestClass', "nonExistentProperty");
new ReflectionProperty('TestClass', "nonExistentProperty");
}
catch(Exception $e) {
catch(ReflectionException $e) {
echo $e->getMessage();
}
@@ -38,7 +37,7 @@ Non-existent class:
Class "NonExistentClass" does not exist
Wrong property parameter type:
ReflectionProperty::__construct(): Argument #1 ($class) must be of type object|string, int given
Class "5" does not exist
Non-existent property:
Property TestClass::$nonExistentProperty does not exist