Re: [RFC] Void Return Type (v0.2, reöp ening)
| From: | Rowan Collins | Date: | Thu, 15 Oct 2015 16:00:31 +0000 |
| Subject: | Re: [RFC] Void Return Type (v0.2, reöp ening) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88819@lists.php.net to get a copy of this message | ||
Andrea Faulds wrote on 15/10/2015 16:32:
Hmm, this is an interesting case you've pointed out. Being able to do return some_other_void_function(); is something I've desired in other languages.
But what if that void function you're calling later adds a return value? Now the calling function is returning a value other than null, violating its type hint and producing a runtime error.
Well, fundamentally, this is true of anything short of full type-checking. The type safety below is self-evident:
function foo(): int { return 42; }
function wrapped_foo(): int { return foo(); }
But foo() could later be changed to this:
function foo(): string { return 'The Answer'; }
The wrapped_foo() typehint is now broken. That's not really any different from foo() starting off as void/returns-null and adding a return value.
In both cases, a static analyser could detect the discrepancy, but the Zend Engine will not, until the function is executed.
It's a shame there's no "tail call this other function and discard its result" construct.Yeah, I guess what you really want is for a void function to be able to "goto foo();" Regards, -- Rowan Collins [IMSoP]