From: Nikita Popov Date: Mon, 21 Oct 2019 14:13:09 +0000 (+0200) Subject: Fix and undeprecate ReflectionType::__toString() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=530a8a38540e36a485f341d487529ade2b5d9c98;p=php Fix and undeprecate ReflectionType::__toString() Add deprecated _ZendTestClass::__toString() method to preserve an existing test. ReflectionType::__toString() will now return a complete representation of the type, as it should have originally. Users that relied on nullability being absent should have been pushed to ReflectionNamedType::getName() by the deprecation of ReflectionType::__toString() in PHP 7.1 / PHP 7.4. --- diff --git a/UPGRADING b/UPGRADING index a0d31617c8..8b2bbfee46 100644 --- a/UPGRADING +++ b/UPGRADING @@ -241,6 +241,11 @@ PHP 8.0 UPGRADE NOTES ReflectionFunction::invoke($arg = null, ...$args) ReflectionMethod::invoke($object, $arg = null, ...$args) + . The ReflectionType::__toString() method will now return a complete debug + representation of the type, and is no longer deprecated. In particular the + result will include a nullability indicator for nullable types. The format + of the return value is not stable and may change between PHP versions. + - Socket: . The deprecated AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES flags for socket_addrinfo_lookup() have been removed. diff --git a/Zend/tests/bug78239.phpt b/Zend/tests/bug78239.phpt index 94908a785b..aa81af4452 100644 --- a/Zend/tests/bug78239.phpt +++ b/Zend/tests/bug78239.phpt @@ -1,5 +1,7 @@ --TEST-- Bug #78239: Deprecation notice during string conversion converted to exception hangs +--SKIPIF-- + --FILE-- getReturnType() ?: ""; +$r = new _ZendTestClass; +(string)$r ?: ""; ?> --EXPECTF-- -Fatal error: Uncaught ErrorException: Function ReflectionType::__toString() is deprecated in %s:%d +Fatal error: Uncaught ErrorException: Function _ZendTestClass::__toString() is deprecated in %s:%d Stack trace: #0 %s(%d): handleError(%s) #1 {main} diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e4a065989a..d3e8a04006 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2818,7 +2818,7 @@ ZEND_METHOD(reflection_type, __toString) } GET_REFLECTION_OBJECT_PTR(param); - RETURN_STR(zend_type_to_string(ZEND_TYPE_WITHOUT_NULL(param->type))); + RETURN_STR(zend_type_to_string(param->type)); } /* }}} */ @@ -6621,7 +6621,7 @@ static const zend_function_entry reflection_parameter_functions[] = { static const zend_function_entry reflection_type_functions[] = { ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) ZEND_ME(reflection_type, allowsNull, arginfo_reflection__void, 0) - ZEND_ME(reflection_type, __toString, arginfo_reflection__void, ZEND_ACC_DEPRECATED) + ZEND_ME(reflection_type, __toString, arginfo_reflection__void, 0) PHP_FE_END }; diff --git a/ext/reflection/tests/ReflectionNamedType.phpt b/ext/reflection/tests/ReflectionNamedType.phpt index afb592127c..78fe1e8fd4 100644 --- a/ext/reflection/tests/ReflectionNamedType.phpt +++ b/ext/reflection/tests/ReflectionNamedType.phpt @@ -30,20 +30,12 @@ var_dump($return->getName()); var_dump((string) $return); ?> ---EXPECTF-- +--EXPECT-- string(11) "Traversable" - -Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d -string(11) "Traversable" -string(6) "string" - -Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d +string(12) "?Traversable" string(6) "string" +string(7) "?string" string(4) "Test" - -Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d -string(4) "Test" -string(4) "Test" - -Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d +string(5) "?Test" string(4) "Test" +string(5) "?Test" diff --git a/ext/reflection/tests/bug72661.phpt b/ext/reflection/tests/bug72661.phpt index 46ba048078..b1cb764beb 100644 --- a/ext/reflection/tests/bug72661.phpt +++ b/ext/reflection/tests/bug72661.phpt @@ -6,6 +6,5 @@ function test(iterable $arg) { } var_dump((string)(new ReflectionParameter("test", 0))->getType()); ?> ---EXPECTF-- -Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d +--EXPECT-- string(8) "iterable" diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index e13ef6257c..8f2e104d1e 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -187,11 +187,21 @@ static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, ze } /* }}} */ +static ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ { + RETURN_EMPTY_STRING(); +} +/* }}} */ + static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ { RETURN_TRUE; } /* }}} */ +static const zend_function_entry zend_test_class_methods[] = { + ZEND_ME(_ZendTestClass, __toString, NULL, ZEND_ACC_DEPRECATED) + ZEND_FE_END +}; + static const zend_function_entry zend_test_trait_methods[] = { ZEND_ME(_ZendTestTrait, testMethod, NULL, ZEND_ACC_PUBLIC) ZEND_FE_END @@ -204,8 +214,8 @@ PHP_MINIT_FUNCTION(zend_test) INIT_CLASS_ENTRY(class_entry, "_ZendTestInterface", NULL); zend_test_interface = zend_register_internal_interface(&class_entry); zend_declare_class_constant_long(zend_test_interface, ZEND_STRL("DUMMY"), 0); - INIT_CLASS_ENTRY(class_entry, "_ZendTestClass", NULL); - zend_test_class = zend_register_internal_class_ex(&class_entry, NULL); + INIT_CLASS_ENTRY(class_entry, "_ZendTestClass", zend_test_class_methods); + zend_test_class = zend_register_internal_class(&class_entry); zend_class_implements(zend_test_class, 1, zend_test_interface); zend_test_class->create_object = zend_test_class_new; zend_test_class->get_static_method = zend_test_class_static_method_get;