Re: proposed access modifier "silent" ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator
| From: | Matthew Weier O'Phinney | Date: | Mon, 11 Apr 2011 18:47:38 +0000 |
| Subject: | Re: proposed access modifier "silent" ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51867@lists.php.net to get a copy of this message | ||
On 2011-04-11, Stas Malyshev <smalyshev@sugarcrm.com> 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