Re: [PHP-DEV] [RFC] Implicit isset() in Shorthand Ternary Operator

[email protected] (Adam Harvey)
Newsgroups php.internals
Message-ID <CADajX4D5QVPhK5GWur+RNimYuw35KTMpkZefcAKAkiaMAj6G_Q@mail.gmail.com>
On 8 September 2014 17:07, Andrea Faulds <[email protected]> wrote:
>
> On 8 Sep 2014, at 23:58, Adam Harvey <[email protected]> wrote:
>
>> +1 on ?? — there's precedent for it, and it means we don't have to
>> explain why the shorthand form of an operator behaves differently to
>> the long form, which is just going to confuse users.
>
> FWIW, it already behaves differently:
>
>     oa-res-27-90:~ ajf$ php -r 'function foo() { echo "foo\n"; return true; } $x = foo() ?: false;'
>     foo
>     oa-res-27-90:~ ajf$ php -r 'function foo() { echo "foo\n"; return true; } $x = foo() ? foo() : false;'
>     foo
>     foo

You could argue whether that's unexpected behaviour or not — there is
only one foo() call in the shorthand version, after all, so it makes
intuitive sense that foo() would only be called once.

Regardless of how you feel about that, though, I don't think
increasing the amount of inconsistency between two versions of the
same operator (forget the implementation; that's how it's documented
and how it's perceived) is a good idea.

Adam
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.