W liście Stanislav Malyshev z dnia piątek 04 stycznia 2008: > > This code is just a good argument *FOR* type hints. When foo is: > > function foo(int $bar) {...} > > and you want the code to die if $bar is not integer, then foo($bar) would > > be > > Why would you want it? I wouldn't want my code to die, I would want it > to work.
You wrote: > With strict checking, that means instead of calling: > foo($bar); > you'd have now to do: > if(is_integer($bar)) { > // stupid foo() call would blow up if passed not integer, so I have > to manually handle it > // oh wait, actually I don't have any way to handle it - I need > foo() to be called to proceed > // so let's just > die("can't call foo() because \$bar is not integer"); > } This shows that you explicitly die() if $bar is not integer. But with strict type hinting this is unneccessary - the script would automatically die if $bar was not integer. In other words, with strict scalar type hinting the above would behave just like foo($bar) with the only difference being the error message (in your version you've got your own error message, automatic script failure would raise some built-in error - which IMO should be E_RECOVERABLE_ERROR, as E_FATAL gives blano output on production sites where display_error is 0). Not that I care if scalar type hinting is implemented or not, I just wanted to point out that your example is just plain wrong. > > > you have either an int or string representing an integer in $bar, then > > foo((integer)$bar) would work just well. > > And then how exactly strict typing helps you? Here it doesn't help, but is easy to work around if you are sure you know what you're doing. This is the same workaround that is needed if someone used if (! is_integer($bar)) {die()} inside of the foo method. -- Paweł Stradomski -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php