Re: Implicit isset in ternary operator
| From: | Alex Aulbach | Date: | Mon, 23 Jul 2012 03:12:19 +0000 |
| Subject: | Re: Implicit isset in ternary operator | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61635@lists.php.net to get a copy of this message | ||
Do we really need that as operator? Why not using new functions for
special cases.
Don't see much difference between
$a = $b ?: $c;
and (for example I used "i" for "if")
$a = _i($b, $c);
Just a manner of getting accustomed to it.
A little bit more thinking: This could be implemented directly into
any program/project, so it is a manner of how to use PHP and not of
why it isn't added to the language.
PS: Would it be possible to implement functions like ":?()" or "!?()"
? Currently this is not allowed by syntax.
2012/7/18 Rafael Dohms <listas@rafaeldohms.com.br>:
> $width = $config['width'] ?: 300;
>
> The only reason for this to not work is: it throws a notice if the array
> key is not there (which is the case we are covering anyway)
>
> This is basically because the ternary operator does not do a internal
> implicit isset, only an empty.
>
> Does this seem like a possible improvement we can work on? Anyone
> interested in championing the change?
--
Alex Aulbach