|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-08-05 00:30 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2018-08-05 00:30 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 15:00:02 2025 UTC |
Description: ------------ One can use an if/then/else construct to conditionally assign a reference to a variable. However, the more compact/readable assignment by means a ternary operator, rejects the "&" before the variable. Test script: --------------- <?php declare(strict_types=1); $myArray = array( [ 'pear', 'sweet' ], [ 'orange', 'sour' ] ); if ( isset( $myArray [5] ) ) $entryRef = &$myArray [5]; else $entryRef = &$myArray [1]; echo $entryRef[1]; // works // Syntax error: $entryRef = isset( $myArray [5] ) ? &$myArray[5] : &$myArray[1]; Expected result: ---------------- $entryRef = &$variable; is a valid assignment - so it seems counterintuitive for the similar assignment $entryRef = condition ? &$variable1 : NULL; to be "invalid syntax". Actual result: -------------- PHP Parse error: syntax error, unexpected '&'