Sent from my iPhone

On Dec 22, 2011, at 7:14 PM, Stas Malyshev <smalys...@sugarcrm.com> wrote:

> Hi!
>
>> 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.
>
> No I am not suggesting that. I'm just pointing out the problems with the 
> concept of strict typing in PHP and this particular instance of it. One of 
> them is that many functions do not actually return one type but multiple 
> types depending on the result. It is a very common pattern.

And in those cases, they would continue to use the keyword "function"
and be considered unknown as they are today.

>
> BTW, which languages you are talking about? PHP peers - Python, Ruby, Perl, 
> Javascript (to some measure), etc. don't have typing as far as I know. 
> Comparing PHP to statically compiled strictly typed languages does not seem 
> very useful to me. So could you clarify what do you mean?

Not seem useful? Then during the discussions of parameter type
hinting, which language did you compare it to? What about abstracts
and interfaces?

I don't compare PHP to ruby, python or JavaScript. Do I suggest
features that I find useful in other languages like C# or Java or even
in any of the ones you listed? Absolutely.

Limiting yourself to comparing features only found in interpreted
languages is a very narrowed scope. Yes, return type validation does
add overhead, just as parameters do (arguably more). But it is a
feature that is very valuable to many. Those who wish not to use it
can continue to do so.

Don't forget that while return checks are runtime, interface
definition and implementations are compile time.

>
>> 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
>
> All functions in PHP return values, so it is not possible that no value would 
> be returned (yes, if you don't return anything it actually will return null). 
> So ensuring something is an object of type X prevents you from returning 
> anything else, false/null included. If you make exceptions for null, then why 
> not for false? If for false, then why not for true? Etc.

Because null is a standard already set by parameter type hints. I do
not want to sway away from that as it works well.  It is common for
null values to be considered "nothing", which is exactly what will be
returned if the specified hint isn't. All or nothing.

> --
> 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

Reply via email to