Re: Unifying logical operators
| From: | David Rodrigues | Date: | Tue, 10 Jul 2018 19:07:58 +0000 |
| Subject: | Re: Unifying logical operators | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102728@lists.php.net to get a copy of this message | ||
I think that "or" could be removed if PHP could supports inline
conditionals like:
die() if !$connected;
throw Exception() if fail();
$x = $y if (z() && w());
Or "when": die() when !$connected;
It seems more clear than $connected or die().
Em ter, 10 de jul de 2018 às 15:59, Andrey Andreev <narf@devilix.net>
escreveu:
> Hi,
>
> On Tue, Jul 10, 2018 at 9:37 PM, Kalle Sommer Nielsen <kalle@php.net>
> wrote:
> > Den tir. 10. jul. 2018 kl. 20.22 skrev Larry Garfield <
> larry@garfieldtech.com>:
> >> "do() or die()" code is/was very common in example code, tutorials, and
> other
> >> intro material because it means you don't need to think about error
> handling.
> >
> > I personally wanted to extend this syntax but I never got around to it
> > to support: "do() or throw new Exception(...);", tho its just a code
> > style over: "if(!do()){ throw new Exception(...); }"
> >
>
> I sometimes declare a closure that throws an exception to do just
> that. It's very convenient in short(ish) scripts.
>
> isset($foo) OR $foo = 'bar'; (and similar variations using empty()
> and/or &&) is another pattern I use often to set fallback values for
> empty or missing inputs.
>
> An eventual deprecation would make literally all of my code output
> entire screens of warnings.
>
> Cheers,
> Andrey.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
David Rodrigues