Re: type hinting throwing a fatal error
From: Zeev Suraski Date: Wed, 10 Aug 2005 15:30:29 +0000 Subject: Re: type hinting throwing a fatal error References: 1 Groups: php.internals Request: Send a blank email to internals+get-17798@lists.php.net to get a copy of this message
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:derick@kossu:~$ cat /tmp/foo.php <?php class foo { function bar(foo $a) { } }$a = new foo; $a->bar(new stdClass); ?> derick@kossu:~$ php /tmp/foo.phpFatal error: Argument 1 must be an instance of foo in /tmp/foo.php on line 3As 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
Thread (125 messages)
| « previous | php.internals (#17798) | next » |
|---|