Bug->Req #70021 [Opn->Sus]: incorrect associativity of ternary operator

From: Date: Mon, 26 Mar 2018 13:30:58 +0000
Subject: Bug->Req #70021 [Opn->Sus]: incorrect associativity of ternary operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214486@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70021&edit=1

 ID:                 70021
 Updated by:         cmb@php.net
 Reported by:        mega at ioexception dot at
 Summary:            incorrect associativity of ternary operator
-Status:             Open
+Status:             Suspended
-Type:               Bug
+Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        7.0Git-2015-07-08 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

Due to the controversial nature of this change, it requires the
RFC process[1].  Anybody is welcome to start it.  For the time
being, I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>


Previous Comments:
------------------------------------------------------------------------
[2015-07-08 13:45:13] cmb@php.net

Oops, wrong link to [1]. Should have been
<http://markmail.org/thread/5bjy2xnu2vrgxxmy>.

------------------------------------------------------------------------
[2015-07-08 13:44:10] cmb@php.net

There has been quite some discussion about this isse last
December[1], but to my knowledge nothing came out of it. Anyhow,
PHP 7.0.0beta1 has already been tagged[2] which is commonly
regarded as feature freeze.

[1] <http://cmsimpleforum.com/viewtopic.php?f=29&t=8821>
[2] <https://github.com/php/php-src/releases/tag/php-7.0.0beta1>

------------------------------------------------------------------------
[2015-07-08 12:37:37] mega at ioexception dot at

A typo has been made in the description. The result in other languages that implement the ternary
operator the result of the test script is 'Toast' not 'Swiss Cheese'.

------------------------------------------------------------------------
[2015-07-08 12:18:28] mega at ioexception dot at

Description:
------------
zend_language_parser.y on line 81 gives the '?:' operator left associativity when 
it should be right as in virtually every other language that has a ternary 
operator. [see also bug 61915]

Due to the massive amount of changes in PHP 7, some of which break backwards compatibility, it would
be a great idea to fix this long standing issue. Although it has been pointed out before that this
behavior is documented it's a non-sane and unconventional result. In other languages that
implement the ternary operator the result of the test script is 'Swiss Cheese'. This
result is expected and conventional.

This issue has been pointed out multiple times before (61915, 25356).



Test script:
---------------
$arg = "3";
$food = (  ($arg == '1') ? 'Banana' :
           ($arg == '2') ? 'Apple' :
           ($arg == '3') ? 'Toast' :
           ($arg == '4') ? 'Cantalope' :
           ($arg == '5') ? 'Swiss Cheese' : 'Fig Newton Cookie'
		 );
echo $food;


Expected result:
----------------
Toast

Actual result:
--------------
Swiss Cheese


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70021&edit=1


Thread (5 messages)

« previous php.bugs (#214486) next »