diff --git a/UPGRADING b/UPGRADING index 49e4edf40e850..f8817889fa972 100644 --- a/UPGRADING +++ b/UPGRADING @@ -306,6 +306,12 @@ PHP 7.4 UPGRADE NOTES . ldap_control_paged_result_response and ldap_control_paged_result are deprecated. Pagination controls can be sent along with ldap_search instead. +- Reflection: + . Calls to ReflectionType::__toString() now generate a deprecation notice. + This method has been deprecated in favor of ReflectionNamedType::getName() + in the documentation since PHP 7.1, but did not throw a deprecation notice + for technical reasons. + ======================================== 5. Changed Functions ======================================== diff --git a/Zend/tests/object_types/return_type_reflection.phpt b/Zend/tests/object_types/return_type_reflection.phpt index bcb918287d167..ac01d90894a20 100644 --- a/Zend/tests/object_types/return_type_reflection.phpt +++ b/Zend/tests/object_types/return_type_reflection.phpt @@ -14,13 +14,13 @@ class Two implements One { function a() : object {} $returnTypeOne = (new ReflectionClass(One::class))->getMethod('a')->getReturnType(); -var_dump($returnTypeOne->isBuiltin(), (string)$returnTypeOne); +var_dump($returnTypeOne->isBuiltin(), $returnTypeOne->getName()); $returnTypeTwo = (new ReflectionClass(Two::class))->getMethod('a')->getReturnType(); -var_dump($returnTypeTwo->isBuiltin(), (string)$returnTypeTwo); +var_dump($returnTypeTwo->isBuiltin(), $returnTypeTwo->getName()); $returnTypea = (new ReflectionFunction('a'))->getReturnType(); -var_dump($returnTypea->isBuiltin(), (string)$returnTypea); +var_dump($returnTypea->isBuiltin(), $returnTypea->getName()); --EXPECT-- bool(true) string(6) "object" diff --git a/Zend/tests/object_types/type_hint_reflection.phpt b/Zend/tests/object_types/type_hint_reflection.phpt index 6a4f27d8c948f..b530e6dc0467b 100644 --- a/Zend/tests/object_types/type_hint_reflection.phpt +++ b/Zend/tests/object_types/type_hint_reflection.phpt @@ -14,13 +14,13 @@ class Two implements One { function a(object $obj) {} $typeHintOne = (new ReflectionClass(One::class))->getMethod('a')->getParameters()[0]->getType(); -var_dump($typeHintOne->isBuiltin(), (string)$typeHintOne); +var_dump($typeHintOne->isBuiltin(), $typeHintOne->getName()); $typeHintTwo = (new ReflectionClass(Two::class))->getMethod('a')->getParameters()[0]->getType(); -var_dump($typeHintTwo->isBuiltin(), (string)$typeHintTwo); +var_dump($typeHintTwo->isBuiltin(), $typeHintTwo->getName()); $typeHinta = (new ReflectionFunction('a'))->getParameters()[0]->getType(); -var_dump($typeHinta->isBuiltin(), (string)$typeHinta); +var_dump($typeHinta->isBuiltin(), $typeHinta->getName()); --EXPECT-- bool(true) string(6) "object" diff --git a/Zend/tests/type_declarations/typed_properties_018.phpt b/Zend/tests/type_declarations/typed_properties_018.phpt index 097b39b232bf1..f3ac4504b1faa 100644 --- a/Zend/tests/type_declarations/typed_properties_018.phpt +++ b/Zend/tests/type_declarations/typed_properties_018.phpt @@ -11,7 +11,7 @@ $reflector = new ReflectionClass(Foo::class); $prop = $reflector->getProperty("qux"); -var_dump((string) $prop->getType()); +var_dump($prop->getType()->getName()); ?> --EXPECT-- string(3) "int" diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4623efb3cf970..ab519251806de 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -6665,10 +6665,7 @@ 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, isBuiltin, arginfo_reflection__void, 0) - /* ReflectionType::__toString() is deprecated, but we currently do not mark it as such - * due to bad interaction with the PHPUnit error handler and exceptions in __toString(). - * See PR2137. */ - ZEND_ME(reflection_type, __toString, arginfo_reflection__void, 0) + ZEND_ME(reflection_type, __toString, arginfo_reflection__void, ZEND_ACC_DEPRECATED) PHP_FE_END }; diff --git a/ext/reflection/tests/ReflectionNamedType.phpt b/ext/reflection/tests/ReflectionNamedType.phpt index a40d4066ec329..afb592127c386 100644 --- a/ext/reflection/tests/ReflectionNamedType.phpt +++ b/ext/reflection/tests/ReflectionNamedType.phpt @@ -30,12 +30,20 @@ var_dump($return->getName()); var_dump((string) $return); ?> ---EXPECT-- +--EXPECTF-- 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(6) "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(4) "Test" diff --git a/ext/reflection/tests/ReflectionType_001.phpt b/ext/reflection/tests/ReflectionType_001.phpt index e47a9615ba56f..1eb521317ceba 100644 --- a/ext/reflection/tests/ReflectionType_001.phpt +++ b/ext/reflection/tests/ReflectionType_001.phpt @@ -91,7 +91,7 @@ $reflector = new ReflectionClass(PropTypeTest::class); foreach ($reflector->getProperties() as $name => $property) { if ($property->hasType()) { printf("public %s $%s;\n", - $property->getType(), $property->getName()); + $property->getType()->getName(), $property->getName()); } else printf("public $%s;\n", $property->getName()); } diff --git a/ext/reflection/tests/bug72661.phpt b/ext/reflection/tests/bug72661.phpt index b1cb764beb62a..46ba048078b75 100644 --- a/ext/reflection/tests/bug72661.phpt +++ b/ext/reflection/tests/bug72661.phpt @@ -6,5 +6,6 @@ function test(iterable $arg) { } var_dump((string)(new ReflectionParameter("test", 0))->getType()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionType::__toString() is deprecated in %s on line %d string(8) "iterable"