Re: com php-src: Append \ to class name returned from ReflectionType::__toString(): ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionNamedType.phpt ext/reflection/tests/ReflectionType_001.phpt ext/reflection/tests/ReflectionType_00

From: Date: Wed, 17 Aug 2016 14:31:56 +0000
Subject: Re: com php-src: Append \ to class name returned from ReflectionType::__toString(): ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionNamedType.phpt ext/reflection/tests/ReflectionType_001.phpt ext/reflection/tests/ReflectionType_00
References: 1 2  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93907@lists.php.net to get a copy of this message
Hi Dmitry, The issue was discussed here: https://github.com/php/php-src/pull/2068 I apologize if I was a bit hasty in committing. As ReflectionType::__toString() is meant to be a syntax valid representation of the type, not prepending the \ would mean libs using it to generate code would have to manually prepend a \. Prepending ? for nullable types complicates things, as libs would have to insert a \ as the second character... not ideal. As Nikita pointed out in the PR discussion, this may get more complicated as things such as callable types are introduced. Since we're already potentially breaking some BC because of nullables, I think now is the time to make this sort of change as well. Aaron Piotrowski > On Aug 17, 2016, at 2:09 AM, Dmitry Stogov <dmitry@zend.com> wrote: > > Hi Aaron, > > This is a behavior change. I'm not sure if it's dangerous, but such changes should be > done only after discussion. (May be I missed it). > > Thanks. Dmitry. > > From: Aaron Piotrowski <trowski@php.net > <mailto:trowski@php.net>> > Sent: Tuesday, August 16, 2016 7:28:33 PM > To: php-cvs@lists.php.net <mailto:php-cvs@lists.php.net> > Subject: [PHP-CVS] com php-src: Append \ to class name returned from > ReflectionType::__toString(): ext/reflection/php_reflection.c > ext/reflection/tests/ReflectionNamedType.phpt ext/reflection/tests/ReflectionType_001.phpt > ext/reflection/tests/ReflectionType_002... > > Commit: 20fdd47921f423728b409fd0ae0106dab9c34573 > Author: Aaron Piotrowski <aaron@trowski.com > <mailto:aaron@trowski.com>> Tue, 16 Aug 2016 > 11:28:33 -0500 > Parents: ba09a520d230506b26ba75e0714131b4ad16d034 > Branches: PHP-7.1 > > Link: > http://git.php.net/?p=php-src.git;a=commitdiff;h=20fdd47921f423728b409fd0ae0106dab9c34573 > <http://git.php.net/?p=php-src.git;a=commitdiff;h=20fdd47921f423728b409fd0ae0106dab9c34573> > > Log: > Append \ to class name returned from ReflectionType::__toString() > > Changed paths: > M ext/reflection/php_reflection.c > M ext/reflection/tests/ReflectionNamedType.phpt > M ext/reflection/tests/ReflectionType_001.phpt > M ext/reflection/tests/ReflectionType_002.phpt > M ext/reflection/tests/ReflectionType_possible_types.phpt > > > Diff: > diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c > index 82d7645..df15efd 100644 > --- a/ext/reflection/php_reflection.c > +++ b/ext/reflection/php_reflection.c > @@ -3037,6 +3037,14 @@ ZEND_METHOD(reflection_type, __toString) > > 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")) { > + str = zend_string_extend(str, ZSTR_LEN(str) + 1, 0); > + memmove(ZSTR_VAL(str) + 1, ZSTR_VAL(str), ZSTR_LEN(str) + 1); > + ZSTR_VAL(str)[0] = '\\' <smb://'>; > + } > + > if (param->arg_info->allow_null) { > str = zend_string_extend(str, ZSTR_LEN(str) + 1, 0); > memmove(ZSTR_VAL(str) + 1, ZSTR_VAL(str), ZSTR_LEN(str) + 1); > diff --git a/ext/reflection/tests/ReflectionNamedType.phpt > b/ext/reflection/tests/ReflectionNamedType.phpt > index 1e8f55a..1ce1222 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(13) "?\Traversable" > string(6) "string" > string(7) "?string" > string(4) "Test" > -string(5) "?Test" > +string(6) "?\Test" > string(4) "Test" > -string(5) "?Test" > +string(6) "?\Test" > \ No newline at end of file > diff --git a/ext/reflection/tests/ReflectionType_001.phpt > b/ext/reflection/tests/ReflectionType_001.phpt > index a317566..c0ae244 100644 > --- a/ext/reflection/tests/ReflectionType_001.phpt > +++ b/ext/reflection/tests/ReflectionType_001.phpt > @@ -79,7 +79,7 @@ foreach ([ > bool(true) > bool(false) > bool(false) > -string(8) "stdClass" > +string(9) "\stdClass" > ** Function 0 - Parameter 1 > bool(true) > bool(false) > @@ -94,7 +94,7 @@ string(8) "callable" > bool(true) > bool(true) > bool(false) > -string(9) "?stdClass" > +string(10) "?\stdClass" > ** Function 0 - Parameter 4 > bool(false) > ** Function 0 - Parameter 5 > @@ -121,19 +121,19 @@ string(5) "float" > bool(true) > bool(false) > bool(false) > -string(11) "NotExisting" > +string(12) "\NotExisting" > ** Function 1 - Parameter 0 > bool(true) > bool(false) > bool(false) > -string(4) "Test" > +string(5) "\Test" > > *** methods > ** Method 0 - parameter 0 > bool(true) > bool(false) > bool(false) > -string(10) "SplSubject" > +string(11) "\SplSubject" > ** Method 1 - parameter 0 > bool(true) > bool(false) > @@ -148,7 +148,7 @@ string(6) "parent" > bool(true) > bool(false) > bool(false) > -string(4) "Test" > +string(5) "\Test" > > *** return types > ** Function/method return type 0 > @@ -157,7 +157,7 @@ bool(false) > bool(true) > bool(false) > bool(false) > -string(8) "stdClass" > +string(9) "\stdClass" > ** Function/method return type 2 > bool(true) > bool(false) > @@ -177,9 +177,9 @@ string(6) "parent" > bool(true) > bool(false) > bool(false) > -string(4) "Test" > +string(5) "\Test" > ** Function/method return type 6 > bool(true) > bool(false) > bool(false) > -string(4) "Test" > +string(5) "\Test" > diff --git a/ext/reflection/tests/ReflectionType_002.phpt > b/ext/reflection/tests/ReflectionType_002.phpt > index 8313862..9c9c77b 100644 > --- a/ext/reflection/tests/ReflectionType_002.phpt > +++ b/ext/reflection/tests/ReflectionType_002.phpt > @@ -12,6 +12,6 @@ unset($rm, $rp); > var_dump((string) $rt, (string) $rrt); > > --EXPECT-- > -string(4) "Test" > -string(5) "Test2" > +string(5) "\Test" > +string(6) "\Test2" > > diff --git a/ext/reflection/tests/ReflectionType_possible_types.phpt > b/ext/reflection/tests/ReflectionType_possible_types.phpt > index 81e0855..0db5b7c 100644 > --- a/ext/reflection/tests/ReflectionType_possible_types.phpt > +++ b/ext/reflection/tests/ReflectionType_possible_types.phpt > @@ -28,4 +28,4 @@ string(6) "string" > string(4) "bool" > string(5) "array" > string(8) "callable" > -string(8) "StdClass" > +string(9) "\StdClass" > > > -- > PHP CVS Mailing List (http://www.php.net/ > <http://www.php.net/>) > To unsubscribe, visit: http://www.php.net/unsub.php > <http://www.php.net/unsub.php>

« previous php.cvs (#93907) next »