I've been in a new team for a few days. Reviewing my code, they have indicated that it is not necessary to put void as the return type of a PHP method... and they deleted it...
Why did they add the void return type to the PHP language? what is your function?
The void return type was introduced in PHP 7.1.
By indicating that a method or function has a return type of void , we indicate that it does not return anything , being valid, for example:
Indicating the void return type improves the readability of the code . We can look at the method or function and, without having to go into its body, know that it doesn't have return statements returning some type of content.
If our code editor allows us to "fold code", for a quick look, we will quickly appreciate the improvement in readability that specifying return types gives us , for example, we could have:
where it is clear that without having to see the implementation of the methods, or use comments, we know if the methods return something or not, and the type if so.
Sources consulted:
php.net - Pseudotypes and variables used
php.net - New features
php.net - Return values
Upgrade to PHP7
According to the PHP documentation in version 7.1 this feature has been introduced.
EXAMPLE 1
It will show this error
Because as its name indicates, a method
void
is thinking not to return valuesReference http://php.net/manual/es/migration71.new-features.php
Since a method of type
void
cannot return a value then this example might give a better example of its use