Re: Return Type Hinting for Methods RFC
| From: | Derick Rethans | Date: | Thu, 22 Dec 2011 23:28:49 +0000 |
| Subject: | Re: Return Type Hinting for Methods RFC | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-57042@lists.php.net to get a copy of this message | ||
On Thu, 22 Dec 2011, Will Fitch wrote:
> Sent from my iPad
> On Dec 22, 2011, at 5:51 PM, "Ángel González" <keisial@gmail.com> wrote:
>
> > Your examples only show class methods with visibility qualifyiers, and
> > looking at the changes to zend_language_parser.y
> > it seems as if would only be available for methods. Wouldn't return
> > hints be available for plain functions?
>
> Right now, it's only available for methods. Personally, I'm not a fan
> of return types for functions. Adding this for functions in its form
> today will also introduce shift/reduce issues.
IMO, it should work for normal functions too.
> > In functional programming, it is common to return nullable types:
> > returns an instance of class Foo or null, an array or false, etc.
> >
> > This is supported in normal arguments with the "= null" hint, and I
> > think there should be something equivalent for return types.
> > Does the proposed implementation allow null everywhere? (there's an
> > example of returning null from a return hint of array)
> > That seems wrong to me. Unless there's a way to make it strict (eg.
> > array! for only arrays).
>
> Most modern languages allow returning null in any case. This is a hail
> Mary in the event something happens, but throwing an exception is
> inappropriate. I see no reason to diverge from that.
I tend to agree with that one.
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug