On Dec 22, 2011, at 6:28 PM, Stas Malyshev <smalys...@sugarcrm.com> wrote:
> Hi! > >> 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. > > In PHP, returning object if everything is OK and false if not is a very > common pattern. > Also, you understand that always allowing null means that this construct: > > $foo = $this->returnsFoo(); > $foo->fooMethod(); > > is no longer safe as you wanted it to be when you made returnsFoo use strict > typing? You'd have to check $foo anyway. Are you suggesting not allowing null to be returned, or provide an indicator within the syntax that it may return null? PHP would be the first language I'm aware of that would do so in either case. The point isn't to restrict a type hint to always be returned. The goal is to guarantee that if a value is returned, it will be of type X. In the event it is inappropriate to return the value back, would you rather receive null or a bogus class instance, empty array or a random function name back? Because that's what will happen. It will become the "workaround" for not being able to return null. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php