]> granicus.if.org Git - php/commitdiff
Do not prepend ? on nullables in ReflectionType::__toString()
authorAaron Piotrowski <aaron@trowski.com>
Sat, 20 Aug 2016 06:06:06 +0000 (01:06 -0500)
committerAaron Piotrowski <aaron@trowski.com>
Sun, 21 Aug 2016 05:12:47 +0000 (00:12 -0500)
Better BC with 7.0.

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 25dcc17898eeff7bf7d3ab7b8fd4abe17d8f6b26..9d6235205b0d89ca46a6097807e5ede7c0affaa2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,13 +2,18 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2016, PHP 7.1.0RC1
 
-- IMAP:
-  . Fixed bug #72852 (imap_mail null dereference). (Anatol)
+- 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)
+
 - XML:
   . Fixed bug #72714 (_xml_startElementHandler() segmentation fault). (cmb)
 
@@ -67,8 +72,8 @@ PHP                                                                        NEWS
 - Reflection:
   . Implemented request #38992 (invoke() and invokeArgs() static method calls
     should match). (cmb).
-  . Add ReflectionNamedType::getName() and return leading "?" for nullable types
-    from ReflectionType::__toString(). (Trowski)
+  . Add ReflectionNamedType::getName(). This method should be used instead of
+    ReflectionType::__toString()
 
 - Session:
   . Implemented RFC: Session ID without hashing. (Yasuo)
index 410a0f25732a6858b8bffab7216cc7f6e373ceb6..71cc31296699c3087b457a51d53514d726c4410d 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -124,9 +124,6 @@ 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
@@ -308,6 +305,9 @@ 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 66ffeab19608e7e06d815708e0b76ca449d0ee0d..a164cbda721bad51400edcf280ca25dbe3eb5532 100644 (file)
@@ -3028,32 +3028,13 @@ 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);
        
-       str = reflection_type_name(param);
-       
-       if (param->arg_info->type_hint == IS_OBJECT
-               && !zend_string_equals_literal_ci(param->arg_info->class_name, "self")
-               && !zend_string_equals_literal_ci(param->arg_info->class_name, "parent")) {
-               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] = '\\';
-       }
-       
-       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);
+       RETURN_STR(reflection_type_name(param));
 }
 /* }}} */
 
index 1e8f55ac9d8a5f001b9847603059d3412cbe2dfe..123e09d51c9820112e9b7599d9acee6a6cfea06b 100644 (file)
@@ -32,10 +32,10 @@ var_dump((string) $return);
 ?>
 --EXPECTF--
 string(11) "Traversable"
-string(12) "?Traversable"
+string(11) "Traversable"
+string(6) "string"
 string(6) "string"
-string(7) "?string"
 string(4) "Test"
-string(5) "?Test"
 string(4) "Test"
-string(5) "?Test"
+string(4) "Test"
+string(4) "Test"
index a31756688761cfbec5e258690c92fac07c59c629..f764cf1519d92a70661fad3cbc852cd99468ba39 100644 (file)
@@ -94,7 +94,7 @@ string(8) "callable"
 bool(true)
 bool(true)
 bool(false)
-string(9) "?stdClass"
+string(8) "stdClass"
 ** Function 0 - Parameter 4
 bool(false)
 ** Function 0 - Parameter 5