I wonder why this is not valid:
Class Foobar
{
private function foo(): void {
return;
}
public function bar(): void {
return $this->foo(); // Compile Error: A void function must not return a value
}
}
I know the RFC says this:
A function with a void return type, or void function, may either return implicitly, or have a return statement without a value
But IMHO foo
is void, thus it should be allowed...
$this->foo()
does not return void
, but null
. So in your bar function, you are actually explicitly returning null
, which is not allowed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.