Re: Re: Improving PHP's type system

From: Date: Fri, 15 Apr 2016 16:30:53 +0000
Subject: Re: Re: Improving PHP's type system
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-92340@lists.php.net to get a copy of this message
On 4/14/16 3:25 PM, Fleshgrinder wrote:
On 4/14/2016 8:59 PM, Stanislav Malyshev wrote: Hi!
I don't know what is complicated about "string|Stringable" or "Foo|Bar" since it is super self-explanatory. However, I find myself checking the
It may be self-explanatory for you. It's much less self-explanatory for somebody just starting to learn. It is also very dangerous - if it's either Foo or Bar, can you call Foo::stuff on it or not? If it's string or not string, can you call strlen on it? Etc., etc. It adds a lot of cognitive load and complicates the whole picture. You may have a specific use case where it is useful (which we have yet to see btw) but please remember it's a language with literally millions of use cases and users. Reduce assertions*, enhance self-documentation, making code more robust,
I disagree here. I think our programs are more robust when programmers avoid passing mixed types and write more simple code instead. Hence I agree with Stas about the danger part. Union type hints are a hazard. Adding them to PHP as a new feature is like saying "here's a great new tool, pick it up and use it" but the tool is really a footgun. Tom

« previous php.internals (#92340) next »