I don't think that's a good idea, regardless of implementation issues.

Calling to a function with the wrong arguments is something that should be dealt with when developing the application, not at runtime. I think that throwing exceptions in all sorts of places encourages people to write 'exception-oriented' apps, which is very messy. Type hinting is also not exactly an OO thing, it's an object thing, and there's a difference. PHP is filling up with a lot of builtin classes, as well as infrastructure classes, that actually simplify the lives of users, without them having to have a clue about object orientation. Some examples that come to mind are SimpleXML, the SOAP classes and PDO. On a long enough timescale - everybody using PHP will be using objects, and many (if not most) of them will be using them in procedural apps. I see a big negative point in forcibly introducing these people to the concept of exceptions.

I believe we mentioned once the possibility of adding another error level, which is fatal - but still catchable by set_error_handler(). That is a good idea (which we should be doing either way).

Zeev

At 12:50 08/08/2005, Derick Rethans wrote:
Hei,

currently if you pass a wrong object's type to a typehinted parameter:

        [EMAIL PROTECTED]:~$ cat /tmp/foo.php
        <?php
        class foo {
                function bar(foo $a)
                {
                }
        }

        $a = new foo;
        $a->bar(new stdClass);
        ?>
        [EMAIL PROTECTED]:~$ php /tmp/foo.php

Fatal error: Argument 1 must be an instance of foo in /tmp/foo.php on
        line 3

As type hinting is a new OO thing, it might perhaps make some sense to
make this an exception instead - as this error might also happen for
dynamic things by people who use the classes you designed. In that case
having this fatal error to stop the whole application can be annoying.
Opinions?

Derick

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to