On Sat, Feb 14, 2015 at 3:28 PM, Stanislav Malyshev <smalys...@gmail.com> wrote:
> Hi! > > > What would be the point of *allowing* returning a value? It's clearly > > It's an error only because you declared it an error. > > > an error. We could let you return anything and then discard it, but > > now you won't spot the error in your code. > > Function return values which are going unused all the time. In PHP, > functions are very frequently called for side effects and not return > values. So returning value and discarding it is a common and perfectly > valid scenario. And it also has absolutely nothing to do with void > declaration - void declaration doesn't cause discarding the value and > you can discard the value with or without it. > > > It's not merely for the sake of it. It makes function signatures more > > descriptive, and lets you catch bugs in your code. > > Only bug it can catch is wrongly declaring the function to be void - > which is introduced by this RFC. For me, it is a clear case of > generating error for the sake of error. > > > We already use void in the manual: why not in PHP? > > Because the manual is the *documentation*, not code. It explains that > the function does not return anything useful. It's not the same as > creating an error when function returns something useful. > One of the primary purposes of having typehints *is* documentation. This applies both to our existing type annotations, to the newly introduced return declarations - and to the void return type. The advantage of having the type declaration be part of the language (rather than a docblock) is brevity on one hand and verification of its correctness on the other hand. It's easy to forget to update docblock type annotations, but you can't get away with specifying an incorrect language-supported annotations - if you use a wrong type annotation your code just won't work. The void return type is actually the one case where we can at compile-time fully verify that it is used correctly - which is great. Allowing to return a value from a void function doesn't make sense. If you want to return a value, don't declare it as void. If you declare it as void, don't return a value. It's really as simple as that. Nikita