]> granicus.if.org Git - php/commitdiff
Revert "Do not prepend ? on nullables in ReflectionType::__toString()"
authorLevi Morrison <levim@php.net>
Tue, 23 Aug 2016 15:42:04 +0000 (09:42 -0600)
committerLevi Morrison <levim@php.net>
Tue, 23 Aug 2016 15:43:31 +0000 (09:43 -0600)
This reverts commit 8855a2ce76e8bfba1d2eea1345c765fde7a9a441.

NEWS
UPGRADING
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionNamedType.phpt
ext/reflection/tests/ReflectionType_001.phpt

diff --git a/NEWS b/NEWS
index ca0f198f945b4063ce3c6c5b058f0cee58b183d4..8b5f0f6aa4338427876854d35fd7cd3636a75eb2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,17 +12,12 @@ PHP                                                                        NEWS
     images). (cmb)
   . Fixed bug #68716 (possible resource leaks in _php_image_convert()). (cmb)
 
-- Reflection:
-  . Reverted prepending \ for class names and ? for nullable types returned
-    from ReflectionType::__toString(). (Trowski)
-
 - Intl:
   . Fixed bug #65732 (grapheme_*() is not Unicode compliant on CR LF
     sequence). (cmb)
 
 - Reflection:
-  . Reverted prepending \ for class names and ? for nullable types returned
-    from ReflectionType::__toString(). (Trowski)
+  . Reverted prepending \ for class names. (Trowski)
 
 - Standard:
   . Fixed bug #72920 (Accessing a private constant using constant() creates
@@ -88,6 +83,8 @@ PHP                                                                        NEWS
     should match). (cmb).
   . Add ReflectionNamedType::getName(). This method should be used instead of
     ReflectionType::__toString()
+  . Prepend \ for class names and ? for nullable types returned from
+    ReflectionType::__toString(). (Trowski)
 
 - Session:
   . Implemented RFC: Session ID without hashing. (Yasuo)
index 71cc31296699c3087b457a51d53514d726c4410d..410a0f25732a6858b8bffab7216cc7f6e373ceb6 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -124,6 +124,9 @@ PHP 7.1 UPGRADE NOTES
   . The behavior of ReflectionMethod::invoke() and ::invokeArgs() has been
     aligned, what causes slightly different behavior than before for some
     pathological cases.
+  . ReflectionType::__toString() will now return the type name with a leading
+    "?" if it is nullable. To retrieve the type name without leading "?" the new
+    ReflectionNamedType::getName() method can be used.
 
 ========================================
 2. New Features
@@ -305,9 +308,6 @@ PHP 7.1 UPGRADE NOTES
 - Reflection:
   . Failure to retrieve a reflection object or retrieve an object property
     will now throw an instance of Error instead of resulting in a fatal error.
-  . ReflectionNamedType will be returned from ReflectionParameter::getType()
-    and ReflectionFunctionAbstract::getReturnType(). This class includes a
-    getName() method that returns the type name as a string.
 
 - Session:
   . Custom session handlers that do not return strings for session IDs will 
index a164cbda721bad51400edcf280ca25dbe3eb5532..cf861b65d81b0c6bcf3481f169101ef46cfce392 100644 (file)
@@ -3028,13 +3028,23 @@ ZEND_METHOD(reflection_type, __toString)
 {
        reflection_object *intern;
        type_reference *param;
+       zend_string *str;
 
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
        GET_REFLECTION_OBJECT_PTR(param);
        
-       RETURN_STR(reflection_type_name(param));
+       str = reflection_type_name(param);
+       
+       if (param->arg_info->allow_null) {
+               size_t orig_len = ZSTR_LEN(str);
+               str = zend_string_extend(str, orig_len + 1, 0);
+               memmove(ZSTR_VAL(str) + 1, ZSTR_VAL(str), orig_len + 1);
+               ZSTR_VAL(str)[0] = '?';
+       }
+       
+       RETURN_STR(str);
 }
 /* }}} */
 
index 123e09d51c9820112e9b7599d9acee6a6cfea06b..1e8f55ac9d8a5f001b9847603059d3412cbe2dfe 100644 (file)
@@ -32,10 +32,10 @@ var_dump((string) $return);
 ?>
 --EXPECTF--
 string(11) "Traversable"
-string(11) "Traversable"
-string(6) "string"
+string(12) "?Traversable"
 string(6) "string"
+string(7) "?string"
 string(4) "Test"
+string(5) "?Test"
 string(4) "Test"
-string(4) "Test"
-string(4) "Test"
+string(5) "?Test"
index f764cf1519d92a70661fad3cbc852cd99468ba39..ee2ebb64dd63c8ea15fc72e0ec6544296a39cd39 100644 (file)
@@ -73,6 +73,8 @@ foreach ([
     var_dump((string)$ra);
   }
 }
+
+?>
 --EXPECT--
 *** functions
 ** Function 0 - Parameter 0
@@ -94,7 +96,7 @@ string(8) "callable"
 bool(true)
 bool(true)
 bool(false)
-string(8) "stdClass"
+string(9) "?stdClass"
 ** Function 0 - Parameter 4
 bool(false)
 ** Function 0 - Parameter 5