Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62769 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67309 invoked from network); 3 Sep 2012 23:01:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2012 23:01:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.173 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.173 smtp173.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.173] ([67.192.241.173:57873] helo=smtp173.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/0E-20751-2C635405 for ; Mon, 03 Sep 2012 19:01:23 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp7.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 33AEF258341; Mon, 3 Sep 2012 19:01:20 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp7.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 8053825813A; Mon, 3 Sep 2012 19:01:19 -0400 (EDT) Message-ID: <504536BE.80309@sugarcrm.com> Date: Mon, 03 Sep 2012 16:01:18 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: Gustavo Lopes CC: "internals@lists.php.net" References: <5040DC47.8000305@ajf.me> <5040F4D9.80206@sugarcrm.com> <5042946A.80204@sugarcrm.com> <5042A7D6.7050001@lerdorf.com> <50452713.3020307@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Are exceptions allowed in php core? From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > First, E_NOTICE exists to permit a compromise between people like Zeev > that think its introduction was an error and that one should be able to > refer to undefined variables and people who prefer a stricter model. For > the programmers that follow this stricter model, an E_NOTICE ends ups > frequently being a fatal (because, for instance, you invoke a method on > the resulting null); some other times you're lucky and you just missed > an "else $var = null" branch, other times the error is far more serious, > like an unintended null -> 0 conversion. So it basically comes to "it doesn't follow but E_NOTICE in fact should be fatal for those who prefer a stricter model because I had some code where it indicated a bug". That's exactly what I was talking about. But PHP is not designed to be this way and PHP code is not written this way, for better or for worse. If you want to start a radical transformation of PHP into something like Python where accessing a value in array that doesn't exist (and pretty much any other unexpected thing) throws an exception that finishes your application (or at least a segment of it inside a catch-all-then-bail-out exception wrapper) - it should not be done in a hush-hush case-by-case basis. It should be announced upfront and consensus should be obtained. I personally do not see such transformation as beneficial, and I suspect many others do not either. But in any case this would not work on case-by-case basis. If however we want to keep the current nature of PHP, introducing fatal errors where it can be avoided only because it _may be_ a bug makes little sense - we have tons of situations where it may be a bug - just as you described with E_NOTICE and no fatal error there. We use fatal error only when there's no logical exit from the situation - like you tell to call a function and it doesn't exist - there's no default we could substitute and there's no logical way to react on it. When we access undefined variable though there is such way - we can assume the variable is empty. We do the same with foreach() - if it's not iterable, we assume no iteration happens. Can it be a bug? Sure it can. Do we produce fatal error in this case? No we do not. Why we should start doing it with generators? Just because they use iterator classes as implementation detail? Doesn't make too much sense to me. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227