com php-src: Revert "Do not prepend ? on nullables in ReflectionType::__toString()": NEWS UPGR ADING ext/reflection/php_reflection.c
ext/reflection/te sts/ReflectionNamedType.phpt ext/reflection/tests/Reflectio nType_001.phpt
| From: | Levi Morrison | Date: | Tue, 23 Aug 2016 15:43:31 +0000 |
| Subject: | com php-src: Revert "Do not prepend ? on nullables in ReflectionType::__toString()": NEWS UPGR ADING ext/reflection/php_reflection.c ext/reflection/te sts/ReflectionNamedType.phpt ext/reflection/tests/Reflectio nType_001.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94053@lists.php.net to get a copy of this message | ||
Commit: f4e68a3968429757719c600ce16913ab09539f0d
Author: Levi Morrison <levim@php.net> Tue, 23 Aug 2016 09:42:04 -0600
Parents: 129e8dadf447df7d98a08447bc8c950b7c9209ec
Branches: PHP-7.1
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f4e68a3968429757719c600ce16913ab09539f0d
Log:
Revert "Do not prepend ? on nullables in ReflectionType::__toString()"
This reverts commit 8855a2ce76e8bfba1d2eea1345c765fde7a9a441.
Changed paths:
M NEWS
M UPGRADING
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionNamedType.phpt
M ext/reflection/tests/ReflectionType_001.phpt
Diff:
diff --git a/NEWS b/NEWS
index ca0f198..8b5f0f6 100644
--- 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)
diff --git a/UPGRADING b/UPGRADING
index 71cc312..410a0f2 100644
--- 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
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index a164cbd..cf861b6 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -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);
}
/* }}} */
diff --git a/ext/reflection/tests/ReflectionNamedType.phpt
b/ext/reflection/tests/ReflectionNamedType.phpt
index 123e09d..1e8f55a 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(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"
diff --git a/ext/reflection/tests/ReflectionType_001.phpt
b/ext/reflection/tests/ReflectionType_001.phpt
index f764cf1..ee2ebb6 100644
--- a/ext/reflection/tests/ReflectionType_001.phpt
+++ b/ext/reflection/tests/ReflectionType_001.phpt
@@ -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