Hi Stas,

Stanislav Malyshev wrote:

I still see no point in this, as every PHP function actually returns
something (at least null). So this type would not actually be right and
would not reflect what actually is happening.

It wouldn't be incorrect. Not all languages with `void` prevent a function's use as an expression (or 'rvalue' in C parlance). In some, it merely requires the function not to explicitly return a value.

And, heck, we use void in the PHP manual all the time.

Moreover, I don't see any scenario where some code depends on a function
not returning something explicitly (i.e. does not use return value) but
function actually returns something explicitly and the calling code
breaks. This appears to be impossible,

It most likely is, but it's not the only case that matters. What if you mistakenly return a value in a function that's not supposed to? This would catch you out.

and thus there's no reason to
declare a function "void" except purely for documentation purposes.
Adding keywords to the language just to document this does not look to
me like a good idea.

I feel that the basic facts about a function should be in the signature, and shouldn't have to be hidden in a comment, if only because it's more concicse and keeps information about parameters on the same line as the parameters themselves. Unlike comments, type hints can't lie, because they're actually enforced.

But, yes, it is mostly just useful for documentation. I can understand your objection there.

Thanks.
--
Andrea Faulds
http://ajf.me/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to