com php-src: Deprecate ReflectionType::__toString() : UPGRADING Zend/tests/object_types/return_type_ref lection.phpt
Zend/tests/object_types/type_hint_reflec tion.phpt Zend/tests/type_declarations/typed_properties _018.phpt ext/reflection/php_reflection.c ext
/reflection/tests/ReflectionNamedType.phpt ext/reflection/t ests/ReflectionType_001.phpt ext/reflection/tests/b ug72661.phpt
| From: | Nikita Popov | Date: | Wed, 05 Jun 2019 13:33:52 +0000 |
| Subject: | com php-src: Deprecate ReflectionType::__toString() : UPGRADING Zend/tests/object_types/return_type_ref lection.phpt Zend/tests/object_types/type_hint_reflec tion.phpt Zend/tests/type_declarations/typed_properties _018.phpt ext/reflection/php_reflection.c ext /reflection/tests/ReflectionNamedType.phpt ext/reflection/t ests/ReflectionType_001.phpt ext/reflection/tests/b ug72661.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106568@lists.php.net to get a copy of this message | ||
Commit: b964298c19c685f61542bbf30c49bd164b67c653
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 5 Jun 2019 15:33:52 +0200
Parents: a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b964298c19c685f61542bbf30c49bd164b67c653
Log:
Deprecate ReflectionType::__toString()
We weren't able to do this in 7.1 because the deprecation notice
may be converted to an exception and __toString() can't throw,
which means that it ultimately become a fatal error. This issue
is resolved now, so we can mark the method as deprecated.
Changed paths:
M UPGRADING
M Zend/tests/object_types/return_type_reflection.phpt
M Zend/tests/object_types/type_hint_reflection.phpt
M Zend/tests/type_declarations/typed_properties_018.phpt
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionNamedType.phpt
M ext/reflection/tests/ReflectionType_001.phpt
M ext/reflection/tests/bug72661.phpt
Diff:
diff --git a/UPGRADING b/UPGRADING
index 49e4edf..f881788 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 bcb9182..ac01d90 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 6a4f27d..b530e6d 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 097b39b..f3ac450 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 4623efb..ab51925 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 a40d406..afb5921 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 e47a961..1eb5213 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 b1cb764..46ba048 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"