Re: [RFC] [PRE-VOTE] Union types

From: Date: Sat, 04 Jun 2016 14:45:46 +0000
Subject: Re: [RFC] [PRE-VOTE] Union types
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-93768@lists.php.net to get a copy of this message
> Am 4.6.2016 um 15:48 schrieb Niklas Keller <me@kelunik.com>: > > Massive is a nice hyperbole here... > Sure, you can check it manually… but why not just always check it manually then? > You then loose possibilities to reflect on it, have static analysis rely on code only > [currently you always have to check docblocks when it's not declared; definitely not an option > for e.g. Optimizer], and a single signature is generally easier to parse for a human. > > Talking about reflection, I'm not happy with the currently proposed solution. > > > ReflectionType::__toString() will now provide a full union type as string; e.g. “int | > > float | NumberObject”. What should it return then, if not this? ReflectionUnionType provides a getTypes() method returning you an array of ReflectionType classes you can access for their individual type. > That requires libraries like Auryn to manually parse that string now. It's no longer > possible to directly use __toString to get the class name. Isn't there a better solution? You’ll have to change your code to respect union types and eventually call ReflectionUnionType::getTypes() in case instanceof returns true. There are already suggestions to give it a better structure (I can only reference https://www.reddit.com/r/PHP/comments/4m93s1/i_want_to_enhance_and_break_the_reflectiontype/ <https://www.reddit.com/r/PHP/comments/4m93s1/i_want_to_enhance_and_break_the_reflectiontype/> here), but fixing this (along with proper nullable handling etc.) is outside of the scope of this RFC. > What about ReflectionType::isBuiltin()? What will it return? Just false? True if only built in > types are used? false. The individual ReflectionTypes in the array returned by ReflectionUnionType::getTypes() will be telling you what they are. > I think allowsNull can be handled as is. Correct. Bob

« previous php.internals (#93768) next »