From 8855a2ce76e8bfba1d2eea1345c765fde7a9a441 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 20 Aug 2016 01:06:06 -0500 Subject: [PATCH] Do not prepend ? on nullables in ReflectionType::__toString() Better BC with 7.0. --- NEWS | 13 ++++++++---- UPGRADING | 6 +++--- ext/reflection/php_reflection.c | 21 +------------------ ext/reflection/tests/ReflectionNamedType.phpt | 8 +++---- ext/reflection/tests/ReflectionType_001.phpt | 2 +- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/NEWS b/NEWS index 25dcc17898..9d6235205b 100644 --- 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) diff --git a/UPGRADING b/UPGRADING index 410a0f2573..71cc312966 100644 --- 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 diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 66ffeab196..a164cbda72 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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)); } /* }}} */ diff --git a/ext/reflection/tests/ReflectionNamedType.phpt b/ext/reflection/tests/ReflectionNamedType.phpt index 1e8f55ac9d..123e09d51c 100644 --- a/ext/reflection/tests/ReflectionNamedType.phpt +++ b/ext/reflection/tests/ReflectionNamedType.phpt @@ -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" diff --git a/ext/reflection/tests/ReflectionType_001.phpt b/ext/reflection/tests/ReflectionType_001.phpt index a317566887..f764cf1519 100644 --- a/ext/reflection/tests/ReflectionType_001.phpt +++ b/ext/reflection/tests/ReflectionType_001.phpt @@ -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 -- 2.40.0