Fair enough :-)
In which case there is a documentation bug, and
the paragraph:
another conditional operator is the "?:" (or ternary)
operator, which operates as in C and many other languages.
might perhaps read better:
another conditional operator is the "?:" (or ternary)
operator, which operates unlike C and all other languages.
;-)
I appreciate the note on the historical accident, and in
which case clearly the behaviour should indeed not be
changed now.
Cheers,
Nick
On Sat, Aug 04, 2001 at 09:21:33PM -0000, Bug Database wrote:
> ID: 12566
> Updated by: jeroen
> Reported By: [EMAIL PROTECTED]
> Status: Open
> Bug Type: *Programming Data Structures
> Operating System: Linux
> PHP Version: 4.0.6
> New Comment:
>
> [EMAIL PROTECTED]:
> > It's not a "bug," but a "feature." :)
> >
> > PHP has the inverse associativity of ?: compared to C (and every other
> > language). This was originally a mistake, but now "it won't be changed,"
> > due to historical reasons.
> >
> > See some messages I had on php-dev back around the first week of January,
> > 2001 on this topic. FWIW, I would like to change it.
> >
> > -adam
>
> So, you need to read it as:
>
> echo (TRUE ? 'one' : TRUE) ? 'two' : 'unknown';,
> and
> echo 'one' ? 'two' : 'unknown' is, correctly, 'two'
>
>
> Maybe a fix for PHP 4.1 / PHP 5?
>
>
>
> Previous Comments:
> ------------------------------------------------------------------------
>
> [2001-08-04 17:04:43] [EMAIL PROTECTED]
>
> Confirmed in latest CVS:
>
> ---
> echo TRUE ? 'one' : TRUE ? 'two' : 'unknown';
> => two
> ---
> echo TRUE ? 'one' : FALSE ? 'two' : 'unknown';
> => two
> ---
> This definitely is a bug, and IMO a serious one. A parse error would be acceptable
>IMO (then use ( and )), but this isn't.
>
> ------------------------------------------------------------------------
>
> [2001-08-04 15:33:28] [EMAIL PROTECTED]
>
> The following emits 'two' rather than 'one' as one would expect.
>
> $a = 1; $b = 2;
>
> echo (($a == 1) ? 'one' :
> ($b == 2) ? 'two' :
> 'unknown');
>
> Apologies if for PHP this unusual behaviour actually is as expected, but being
>counter-intuituve, and of course inconsistent from other languages with a ?:
>operator, this is an undesirable result.
>
> In 'C', the following of course outputs 'one'
>
> #include <stdio.h>
>
> int main()
> {
> int a = 1, b = 2;
>
> puts((a == 1) ? "one" :
> (b == 2) ? "two" :
> "unknown");
>
> return 0;
> }
>
>
> ------------------------------------------------------------------------
>
>
>
> ATTENTION! Do NOT reply to this email!
> To reply, use the web interface found at http://bugs.php.net/?id=12566&edit=2
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]