Reflection API and Nullable Types

php.internals

Sebastian Bergmann

9 years ago
At some point in time during the development of PHP 7.1 this code function f(?int $x) { } $f = new ReflectionFunction('f'); var_dump((string) $f->getParameters()[0]->getType()); var_dump($f->getParameters()[0]->getType()->getName()); printed string(4) "?int" string(3) "int" and now it prints string(4) "int" string(3) "int" I know that this issue (or a similar one) was recently discussed but after reading through that thread I am not 100% sure whether the current behavior is indeed the intended one. Thanks! Sebastian

Niklas Keller

9 years ago
Sebastian Bergmann <sebastian@php.net> schrieb am So., 9. Okt. 2016, 08:56:
> At some point in time during the development of PHP 7.1 this code > > function f(?int $x) > { > } > > $f = new ReflectionFunction('f'); > > var_dump((string) $f->getParameters()[0]->getType()); > var_dump($f->getParameters()[0]->getType()->getName()); > > printed > > string(4) "?int" > string(3) "int" > > and now it prints > > string(4) "int" > string(3) "int" > > I know that this issue (or a similar one) was recently discussed but after > reading through that thread I am not 100% sure whether the current > behavior is indeed the intended one. >
See http://externals.io/thread/321 The change has been made to provide backwards compatibility. __toString is now deprecated and getName should be used. Regards, Niklas Thanks!

Stas Malyshev

9 years ago
Hi!
> printed > > string(4) "?int" > string(3) "int" > > and now it prints > > string(4) "int"
<pedantic>I hope it's string(3) otherwise we have a bug on our hands</pedantic>
-- Stas Malyshev smalyshev@gmail.com

Sebastian Bergmann

9 years ago
On 10/11/2016 07:27 AM, Stanislav Malyshev wrote:
> <pedantic>I hope it's string(3) otherwise we have a bug on our > hands</pedantic>
That was a copy/pasta/no-adapt mistake, my bad.