Req #62435 [Opn->Nab]: Shorted if and references handling
Edit report at https://bugs.php.net/bug.php?id=62435&edit=1
ID: 62435
Updated by: krakjoe@php.net
Reported by: grzegorz129 at gmail dot com
Summary: Shorted if and references handling
-Status: Open
+Status: Not a bug
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:
This appears to stem from misunderstanding.
Previous Comments:
------------------------------------------------------------------------
[2012-10-26 19:14:16] 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.
------------------------------------------------------------------------
[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
Thread (3 messages)