Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:371 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55075 invoked from network); 27 Mar 2003 16:57:19 -0000 Received: from unknown (HELO marco.bezeqint.net) (192.115.106.37) by pb1.pair.com with SMTP; 27 Mar 2003 16:57:19 -0000 Received: from mr2.bezeqint.net (pip-17.bezeqint.net [192.115.106.17]) by marco.bezeqint.net (Bezeq International SMTP out Mail Server) with ESMTP id 3220D697 for ; Thu, 27 Mar 2003 18:55:43 +0200 (IST) Received: from mail.zend.com (bzq-117-235-230.cust.bezeqint.net [192.117.235.230]) by mr2.bezeqint.net (Mirapoint Messaging Server MOS 3.3.3-GR) with SMTP id AVG99492; Thu, 27 Mar 2003 18:57:13 +0200 (IST) Received: (qmail 2354 invoked from network); 27 Mar 2003 16:57:05 -0000 Received: from localhost (HELO andi-laptop.zend.com) (127.0.0.1) by localhost with SMTP; 27 Mar 2003 16:57:05 -0000 Message-ID: <5.1.0.14.2.20030327185529.0418b2e0@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 27 Mar 2003 18:58:03 +0200 To: Timm Friebe , engine2@lists.zend.com Cc: internals@lists.php.net In-Reply-To: <1048781764.25691.593.camel@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [Zend Engine 2] Type hints revisited [IllegalArgumentException instead of E_ERROR] From: andi@zend.com (Andi Gutmans) References: <1048781764.25691.593.camel@localhost> At 05:16 PM 3/27/2003 +0100, Timm Friebe wrote: >I've implemented an additional feature for type hints that will throw an >exception instead of bailing out in case an incorrect type is passed. I don't see any major advantage in doing this. I think we should keep PHP error handling the same as in PHP 4 and leave exceptions in user-land. Otherwise we'll end up having an unmanageable hybrid because there's no way we're going to change the error-handling of the existing internal functions. The majority of our user base is still functional, please don't forget this. I feel that people here tend to forget that. Andi >Test script: > > class Date { } > class Article { > public function setCreated_at(Date $date) { > echo __CLASS__, '::', __FUNCTION__, ' called with '; > var_export($date); > echo "\n"; > } > > public function setLastchange([Date] $date) { > echo __CLASS__, '::', __FUNCTION__, ' called with '; > var_export($date); > echo "\n"; > } > } > > $a= new Article(); > $a->setLastchange(new Date()); > $a->setLastchange(NULL); // Passes > $a->setCreated_at(new Date()); > > try { > $a->setCreated_at(NULL); // Fails > } catch (IllegalArgumentException $e) { > echo "Caught: "; var_dump($e); > } > > $a->setCreated_at(1); // Fails > echo "Alive"; // Will not show up >?> > >Output: >--------------------------------------------------------------------- >thekid@friebes:~/devel/php > ./php5/sapi/cli/php hints.php >article::setlastchange called with class date { >} >article::setlastchange called with NULL >article::setcreated_at called with class date { >} >Caught: object(illegalargumentexception)#2 (3) { > ["message"]=> > string(38) "Argument 1 must be an instance of date" > ["file"]=> > string(36) "/usr/home/thekid/devel/php/hints.php" > ["line"]=> > int(4) >} > >Fatal error: Uncaught exception! in Unknown on line 0 >--------------------------------------------------------------------- > >A unified diff is attached. > >- Timm