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]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php