Req #62435 [Com]: Shorted if and references handling
| From: | dagguh at gmail dot com | Date: | Fri, 26 Oct 2012 19:14:17 +0000 |
| Subject: | Req #62435 [Com]: Shorted if and references handling | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174368@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62435&edit=1
ID: 62435
Comment by: dagguh at gmail dot com
Reported by: grzegorz129 at gmail dot com
Summary: Shorted if and references handling
Status: Open
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: N/A
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
"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.
Previous Comments:
------------------------------------------------------------------------
[2012-06-28 09:41:09] 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];
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62435&edit=1