Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17798 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7418 invoked by uid 1010); 10 Aug 2005 15:30:35 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 7403 invoked from network); 10 Aug 2005 15:30:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2005 15:30:34 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:56850] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 5C/BD-24081-99D1AF24 for ; Wed, 10 Aug 2005 11:30:34 -0400 Received: (qmail 8505 invoked from network); 10 Aug 2005 15:30:29 -0000 Received: from localhost (HELO zeev-notebook.zend.com) (127.0.0.1) by localhost with SMTP; 10 Aug 2005 15:30:29 -0000 Message-ID: <5.1.0.14.2.20050810181848.07a678e0@localhost> X-Sender: zeev@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 10 Aug 2005 18:30:29 +0300 To: Derick Rethans Cc: PHP Developers Mailing List In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] type hinting throwing a fatal error From: zeev@zend.com (Zeev Suraski) References: 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 > class foo { > function bar(foo $a) > { > } > } > > $a = new foo; > $a->bar(new stdClass); > ?> > derick@kossu:~$ 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