Edit report at https://bugs.php.net/bug.php?id=54740&edit=1

 ID:                 54740
 Updated by:         m...@php.net
 Reported by:        dukeofgaming at gmail dot com
 Summary:            Ternary operator will not work with return by
                     reference
-Status:             Open
+Status:             Not a bug
 Type:               Bug
-Package:            Compile Failure
+Package:            Scripting Engine problem
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Check the second note here:
http://php.net/manual/en/language.references.return.php


Previous Comments:
------------------------------------------------------------------------
[2012-08-27 14:17:44] marrch dot caat at gmail dot com

This is a general problem with reference inside ternary operator. For ex., the 
following script fails with the same error:
$link = isset($i) ? (& $arr[$i]) : null;
- while the following works fine:
$link = & $arr[$i];

------------------------------------------------------------------------
[2011-05-15 22:59:17] dukeofgaming at gmail dot com

Description:
------------
PHP fails to parse a returned by reference value when using the ternary 
operator. 
The test script provided illustrates a case of when it is absolutely necessary 
to return by reference; if the "&" is removed then the output would be a fatal 
error: "Fatal error: Cannot use [] for reading in <...>"

Test script:
---------------
$value  = ($condition)?(
    $some_value
):(&$object->Collection[]);

Expected result:
----------------
No errors, should be the equivalent of having:

if($condition){
    $value = $some_value;
}else{
    $value = &$object->Collection[];
}

Actual result:
--------------
Parse error: syntax error, unexpected '&' in <...>


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54740&edit=1

Reply via email to