Re: New syntax proposal (type hinting)

From: Date: Sat, 23 Mar 2019 21:03:22 +0000
Subject: Re: New syntax proposal (type hinting)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-104905@lists.php.net to get a copy of this message
On Sat, 23 Mar 2019 at 20:17, dj.drezyna <dj_drezyna@wp.pl> wrote: > > I wish have opportunity to set types not only like: function a(): string {} or function > b(): ?string {} > but also as: function c(): string | int {} or function d(): ?string | ?array {}// all of > them should mark > that null is accepted. Looks like you're asking for union types. There was an RFC about this before but it didn't pass, I don't know why. https://wiki.php.net/rfc/union_types I would also like to see union types added, as I can't type hint most of my code in absence of them. Regarding the type coalescing problem noted in that RFC, my solution to that would be to do noting. If a function accepts float or int, it should just pass either through unchanged. Passing any other type should be an error without an explicit cast IMO.

« previous php.internals (#104905) next »