Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51867 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37014 invoked from network); 11 Apr 2011 18:47:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2011 18:47:39 -0000 X-Host-Fingerprint: 208.107.178.23 host-23-178-107-208.midco.net Date: Mon, 11 Apr 2011 14:47:38 -0400 Received: from [208.107.178.23] ([208.107.178.23:27858] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/C1-24294-9CC43AD4 for ; Mon, 11 Apr 2011 14:47:38 -0400 Message-ID: <23.C1.24294.9CC43AD4@pb1.pair.com> To: internals@lists.php.net References: <4DA26602.6080303@lorenso.com> <20110411133657.GK7113@crousti> <4DA3468E.8000509@sugarcrm.com> User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 208.107.178.23 Subject: Re: [PHP-DEV] proposed access modifier "silent" ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: weierophinney@php.net (Matthew Weier O'Phinney) On 2011-04-11, Stas Malyshev wrote: > > I might come off rather crumudgeonly here, but these last few > > threads I've seen going across to silence notices have a common > > theme - "I wanna be a lazier coder." > > Laziness is a virtue for a coder :) At least, when it goes to avoid > unnecessary work - in this example, boilerplate code. > > > Which is fine - set the PHP error level to not show them. > > This is not good enough - "not showed" errors are still generated and > are quite expensive. > > > But don't ask the engine to be rewritten to encourage bad coding > > practices which failing to properly initialize variables is a prime > > example of. It's > > The case we're dealing with is specifically about providing resolution > for the case when the value is not initialized and the default value > is provided. It is about making good code easier to write ("$foo[$bar] > ?? $baz" instead of "isset($foo[$bar])?$foo[$bar]:$bar"). +1 This is precisely the use case I originally (erroneously) thought the ternary shortcut was for. It's not uncommon to use nested arrays or objects for configuration -- and configuration is one place where you may or may not have values. Having a shortcut to retrieve the value if present or provide a default is not just laziness, but also a way to improve your coding -- by removing yet another place for a typo. (Type the array/object access ONCE instead of TWICE.) -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc