com php-src: Fix and undeprecate ReflectionType::__toSt ring(): UPGRADING Zend/tests/bug78239.php t ext/reflection/php_reflection.c
ext/reflection/tests/ ReflectionNamedType.phpt ext/reflection/tests/bug726 61.phpt ext/zend_test/test.c
| From: | Nikita Popov | Date: | Tue, 22 Oct 2019 09:26:02 +0000 |
| Subject: | com php-src: Fix and undeprecate ReflectionType::__toSt ring(): UPGRADING Zend/tests/bug78239.php t ext/reflection/php_reflection.c ext/reflection/tests/ ReflectionNamedType.phpt ext/reflection/tests/bug726 61.phpt ext/zend_test/test.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109000@lists.php.net to get a copy of this message | ||
Commit: 530a8a38540e36a485f341d487529ade2b5d9c98
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 21 Oct 2019 16:13:09 +0200
Parents: 1faea28cdd3677e47a0951367571bf51866105fd
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=530a8a38540e36a485f341d487529ade2b5d9c98
Log:
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.
Changed paths:
M UPGRADING
M Zend/tests/bug78239.phpt
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionNamedType.phpt
M ext/reflection/tests/bug72661.phpt
M ext/zend_test/test.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index a0d31617c88..8b2bbfee460 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 94908a785b5..aa81af44520 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--
+<?php if (!extension_loaded("zend-test")) die("skip requires zend-test
extension"); ?>
--FILE--
<?php
function handleError($level, $message, $file = '', $line = 0, $context = [])
@@ -9,21 +11,12 @@ function handleError($level, $message, $file = '', $line = 0, $context
= [])
set_error_handler('handleError');
-class A
-{
-
- public function abc(): bool
- {
- return false;
- }
-}
-
-$r = new ReflectionMethod("A", "abc");
-(string)$r->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 e4a065989a7..d3e8a040068 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 afb592127c3..78fe1e8fd43 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 46ba048078b..b1cb764beb6 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 e13ef6257cb..8f2e104d1ea 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;