When I have a function like this:
public function getResult() {
return;
}
Is it the exactly same as returning null? And if I'd be doing this:
is_null($this->getResult());
Would that result in true?
In terms of runtime behaviour, no, there is not. All functions implicitly return a NULL
, and return
with no value (so return;
) produces a NULL
return value.
If you use the : void
return type declaration in PHP 7.1+, return NULL;
(instead of return;
) is forbidden, but this is really just a coding-style restriction. Function calls always produce some value in PHP, so var_dump((function (): void {})());
outputs NULL
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With