]> granicus.if.org Git - php/commitdiff
Fix and undeprecate ReflectionType::__toString()
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 21 Oct 2019 14:13:09 +0000 (16:13 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Oct 2019 09:26:02 +0000 (11:26 +0200)
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.

UPGRADING
Zend/tests/bug78239.phpt
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionNamedType.phpt
ext/reflection/tests/bug72661.phpt
ext/zend_test/test.c

index a0d31617c88c23fba958dd87fa7115286a50a0ce..8b2bbfee460f145102e4d69287d6f304692e5872 100644 (file)
--- 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.
index 94908a785b5c717a8bb29395d8adf099bcf1af6c..aa81af44520cd4aaabd642478fd26e566aadddf2 100644 (file)
@@ -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}
index e4a065989a7558b024931f345a3fcccae45ab7cb..d3e8a0400680350cce1fc6fc7d1f8ee9abdbd3e5 100644 (file)
@@ -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
 };
 
index afb592127c3863b4afb8ffe69ec80dd5349a9622..78fe1e8fd43ee5200abda67ffd579bcb0627cc54 100644 (file)
@@ -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"
index 46ba048078b75cf773f2123f12e5704f0d5f6e6c..b1cb764beb62ad4a8df12d5f047d29e4e6e00aae 100644 (file)
@@ -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"
index e13ef6257cb947500ce438cc71aa63342a35d25e..8f2e104d1ea3883c416f5301a723fd5c9b74d86d 100644 (file)
@@ -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;