php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62435 Shorted if and references handling
Submitted: 2012-06-28 09:41 UTC Modified: 2013-11-02 16:24 UTC
Votes:3
Avg. Score:1.7 ± 0.9
Reproduced:0 of 1 (0.0%)
From: grzegorz129 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.4 OS: N/A
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grzegorz129 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-06-28 09:41 UTC] grzegorz129 at gmail dot com
Description:
------------
PHP doesn't allow to use references in short if construction - I don't have idea 
why it's limited. I think it should be improved in future releases.

Test script:
---------------
$this->_currentExceptionInfo = ((isset($this->_exceptionsMap[$code])) ? &$this->_exceptionsMap[$code] : &$this->_exceptionsMap[self::X_INTERNAL]); //Error

//The same function but it works as expected
if(isset($this->_exceptionsMap[$code])) $this->_currentExceptionInfo = &$this->_exceptionsMap[$code];
else $this->_currentExceptionInfo = &$this->_exceptionsMap[self::X_INTERNAL];


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-26 19:14 UTC] dagguh at gmail dot com
"Short if" is known as ternary operator.

What you want to write is:
$this->_currentExceptionInfo =& ((isset($this->_exceptionsMap[$code])) ? $this-
>_exceptionsMap[$code] : $this->_exceptionsMap[self::X_INTERNAL]);

BTW. Using references is a bad idea.
This request is invalid.
 [2013-11-02 16:24 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-11-02 16:24 UTC] krakjoe@php.net
This appears to stem from misunderstanding.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 04:01:30 2025 UTC