Skip to content

Commit 8855a2c

Browse files
committed
Do not prepend ? on nullables in ReflectionType::__toString()
Better BC with 7.0.
1 parent 08c5d77 commit 8855a2c

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

NEWS

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2016, PHP 7.1.0RC1
44

5-
- IMAP:
6-
. Fixed bug #72852 (imap_mail null dereference). (Anatol)
5+
- Reflection:
6+
. Reverted prepending \ for class names and ? for nullable types returned
7+
from ReflectionType::__toString(). (Trowski)
78

89
- Intl:
910
. Fixed bug #65732 (grapheme_*() is not Unicode compliant on CR LF
1011
sequence). (cmb)
1112

13+
- Reflection:
14+
. Reverted prepending \ for class names and ? for nullable types returned
15+
from ReflectionType::__toString(). (Trowski)
16+
1217
- XML:
1318
. Fixed bug #72714 (_xml_startElementHandler() segmentation fault). (cmb)
1419

@@ -67,8 +72,8 @@ PHP NEWS
6772
- Reflection:
6873
. Implemented request #38992 (invoke() and invokeArgs() static method calls
6974
should match). (cmb).
70-
. Add ReflectionNamedType::getName() and return leading "?" for nullable types
71-
from ReflectionType::__toString(). (Trowski)
75+
. Add ReflectionNamedType::getName(). This method should be used instead of
76+
ReflectionType::__toString()
7277

7378
- Session:
7479
. Implemented RFC: Session ID without hashing. (Yasuo)

UPGRADING

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ PHP 7.1 UPGRADE NOTES
124124
. The behavior of ReflectionMethod::invoke() and ::invokeArgs() has been
125125
aligned, what causes slightly different behavior than before for some
126126
pathological cases.
127-
. ReflectionType::__toString() will now return the type name with a leading
128-
"?" if it is nullable. To retrieve the type name without leading "?" the new
129-
ReflectionNamedType::getName() method can be used.
130127

131128
========================================
132129
2. New Features
@@ -308,6 +305,9 @@ PHP 7.1 UPGRADE NOTES
308305
- Reflection:
309306
. Failure to retrieve a reflection object or retrieve an object property
310307
will now throw an instance of Error instead of resulting in a fatal error.
308+
. ReflectionNamedType will be returned from ReflectionParameter::getType()
309+
and ReflectionFunctionAbstract::getReturnType(). This class includes a
310+
getName() method that returns the type name as a string.
311311

312312
- Session:
313313
. Custom session handlers that do not return strings for session IDs will

ext/reflection/php_reflection.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,32 +3028,13 @@ ZEND_METHOD(reflection_type, __toString)
30283028
{
30293029
reflection_object *intern;
30303030
type_reference *param;
3031-
zend_string *str;
30323031

30333032
if (zend_parse_parameters_none() == FAILURE) {
30343033
return;
30353034
}
30363035
GET_REFLECTION_OBJECT_PTR(param);
30373036

3038-
str = reflection_type_name(param);
3039-
3040-
if (param->arg_info->type_hint == IS_OBJECT
3041-
&& !zend_string_equals_literal_ci(param->arg_info->class_name, "self")
3042-
&& !zend_string_equals_literal_ci(param->arg_info->class_name, "parent")) {
3043-
size_t orig_len = ZSTR_LEN(str);
3044-
str = zend_string_extend(str, orig_len + 1, 0);
3045-
memmove(ZSTR_VAL(str) + 1, ZSTR_VAL(str), orig_len + 1);
3046-
ZSTR_VAL(str)[0] = '\\';
3047-
}
3048-
3049-
if (param->arg_info->allow_null) {
3050-
size_t orig_len = ZSTR_LEN(str);
3051-
str = zend_string_extend(str, orig_len + 1, 0);
3052-
memmove(ZSTR_VAL(str) + 1, ZSTR_VAL(str), orig_len + 1);
3053-
ZSTR_VAL(str)[0] = '?';
3054-
}
3055-
3056-
RETURN_STR(str);
3037+
RETURN_STR(reflection_type_name(param));
30573038
}
30583039
/* }}} */
30593040

ext/reflection/tests/ReflectionNamedType.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ var_dump((string) $return);
3232
?>
3333
--EXPECTF--
3434
string(11) "Traversable"
35-
string(12) "?Traversable"
35+
string(11) "Traversable"
36+
string(6) "string"
3637
string(6) "string"
37-
string(7) "?string"
3838
string(4) "Test"
39-
string(5) "?Test"
4039
string(4) "Test"
41-
string(5) "?Test"
40+
string(4) "Test"
41+
string(4) "Test"

ext/reflection/tests/ReflectionType_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ string(8) "callable"
9494
bool(true)
9595
bool(true)
9696
bool(false)
97-
string(9) "?stdClass"
97+
string(8) "stdClass"
9898
** Function 0 - Parameter 4
9999
bool(false)
100100
** Function 0 - Parameter 5

0 commit comments

Comments
 (0)