On Sat, 2003-03-29 at 13:10, Zeev Suraski wrote:
[...]
> >After reading through a bunch of mails this generated, I get the idea
> >that most people here would be happier with an E_WARNING and the
> >function not being executed.
>
> ?!
>
> How the heck can we even think about such a thing? When you call a
> function, you expect it to run. The code that follows it may rely on stuff
> that it has done. Not running it is simply not an option, I can't even
> begin to imagine the possible consequences of such an approach!
Well, at the moment, the function is not run either, isn't it? The
program dies.
To clarify:
function foo(Bar $bar) {
// [...]
}
is - with my patch - equivalent to:
function foo($bar) {
if (!($bar instanceof Bar)) {
trigger_error('Argument 1 must be an instance of Bar', E_WARNING);
return;
}
// [...]
}
and basically much nicer as a function containing - say - five or six
arguments all needing to be checked in the "not-instance-of" manner.
At the moment, it is:
function foo($bar) {
if (!($bar instanceof Bar)) {
die('Argument 1 must be an instance of Bar');
}
// [...]
}
That's all I changed.
> Type hints are shortcuts for instanceof. If you want to handle a situation
> where the function is passed the wrong arguments, don't use type hints, use
> instanceof. Or use the errors-for-exceptions mode that we may have.
I guess, as we can't find a consensus here, that is what has to be done.
- Timm
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php