RE: [PHP-DEV] Return Type Hinting for Methods RFC
| From: | John Crenshaw | Date: | Fri, 23 Dec 2011 12:10:10 +0000 |
| Subject: | RE: [PHP-DEV] Return Type Hinting for Methods RFC | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-57057@lists.php.net to get a copy of this message | ||
> From: Will Fitch [mailto:will.fitch@gmail.com]
>
> I would like to take this opportunity to query on a consensus:
>
> Would you prefer to allow methods with type hinted return values to return null at will, or add
> a marker noting that it *may* return null?
>
> Example: Return null at will
>
> public ArrayIterator getIterator()
> {
> // something happened, will return null
> return null;
> }
>
> Example: Return only if identified as such
>
> public ArrayIterator? getIterator()
> {
> return null;
> }
I hate the syntax in the second example (using ?).
IMO allowing null should be the default unless specifically disallowed.
I far prefer the addition/use of a keyword ("notnull" or "null") to disallow (or
allow) as opposed to random symbol abuse (potential incompatibilities notwithstanding).
John Crenshaw
Priacta, Inc.