php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18121 Ternary Conditional Operator does not allow references as values.
Submitted: 2002-07-02 18:41 UTC Modified: 2002-08-20 18:10 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: russ at zerotech dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.1 OS: All Platforms
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: russ at zerotech dot net
New email:
PHP Version: OS:

 

 [2002-07-02 18:41 UTC] russ at zerotech dot net
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-20 18:10 UTC] cardinal@php.net
This isn't a bug, as we discussed in #php.

Bogusifying.

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC