Bug #18121: Ternary Conditional Operator does not allow references as values.

From: Date: Tue, 02 Jul 2002 22:41:12 +0000
Subject: Bug #18121: Ternary Conditional Operator does not allow references as values.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12887@lists.php.net to get a copy of this message
From: russ@zerotech.net Operating system: All Platforms PHP version: 4.2.1 PHP Bug Type: Variables related Bug description: Ternary Conditional Operator does not allow references as values. Additional Note: This bug was tested on PHP 4.2.1 AND PHP CVS as of Today, July 2nd, 2002. Using References inside a Ternary Conditional Operator generates a general parse error. Consider the following example that tests usage with both Superglobals and regular variables: <?PHP error_reporting(E_ALL); /* This demonstrates a bug in the ternary conditional operator. It does not seem to allow references to be values. */ // Tested Using Superglobals // ---- // This works $request = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET; // This however does not. $request = ($_SERVER['REQUEST_METHOD'] == 'POST') ? &$_POST : &$_GET; // Tested Using Regular Variables // ---- $foo = "Foo"; $bar = "Bar"; // This works $foobar = 1 ? $foo : $bar; // This however does not. $foobar = 1 ? &$foo : &$bar; ?> When this is run, it generates a parse error similar this this .. Parse error: parse error in /home/russ/repository/qaweb/test.php on line 19 .. on the lines in which references are used in the ternary conditional operator. Since a reference is considered a type, and can be in an assignment operator, such as $var = &$ref, there is no reason it shouldn't work inside the ternary conditional operator which is basically an assignment operator with control. -- Edit bug report at http://bugs.php.net/?id=18121&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=18121&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=18121&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=18121&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=18121&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=18121&r=support Expected behavior: http://bugs.php.net/fix.php?id=18121&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=18121&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=18121&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=18121&r=globals

« previous php.bugs (#12887) next »