Bug #71948 [Opn->Dup]: Variables by reference with goto and switch broken as of 7.0.5
Edit report at https://bugs.php.net/bug.php?id=71948&edit=1
ID: 71948
Updated by: bwoebi@php.net
Reported by: dane dot tschi at gmail dot com
Summary: Variables by reference with goto and switch broken
as of 7.0.5
-Status: Open
+Status: Duplicate
Type: Bug
Package: Variables related
Operating System: Unix/OSX
PHP Version: 7.0.5
Block user comment: N
Private report: N
New Comment:
Duplicate of #71914
Previous Comments:
------------------------------------------------------------------------
[2016-04-02 14:28:24] peter at nonumber dot nl
This is probably the same issue.
I have this code:
-------------
<?php
echo '<p>[PHP VERSION: '.phpversion().']</p>';
$state = 'foo';
toggle($state);
echo $state; // in php 7.0.5 : still foo!
function toggle(&$state)
{
switch ($state)
{
case 'foo':
$state = 'bar';
break;
case 'bar':
$state = 'foo';
break;
}
}
-------------
------------------------------------------------------------------------
[2016-04-02 13:33:09] dane dot tschi at gmail dot com
Updated title
------------------------------------------------------------------------
[2016-04-02 13:32:02] dane dot tschi at gmail dot com
Description:
------------
We tried upgrading from php 7.0.4 to 7.0.5. Unfortunately zendframework stopped working. After
debugging I came up with a reduced testcase that reproduces the issue.
On php 7.0.4 it outputs the expected result, on 7.0.5 the wrong result.
This only happens if the switch-case is in there, if i replace it with if/else it works.
Test script:
---------------
<?php
$tokenIndex = 0;
$tokens = [T_WHITESPACE, T_CLASS];
$tokenType = null;
$MACRO_TOKEN_ADVANCE = function () use (&$tokenType, &$tokenIndex, $tokens) {
if (!isset($tokens[$tokenIndex])) return false;
$tokenType = $tokens[$tokenIndex++];
return $tokenType;
};
$MACRO_TOKEN_ADVANCE();
SCANNER_TOP:
switch($tokenType) {
case T_WHITESPACE: echo "whitespace"; break;
case T_CLASS: echo "class"; break;
}
if ($MACRO_TOKEN_ADVANCE() !== false) goto SCANNER_TOP;
Expected result:
----------------
whitespaceclass
Actual result:
--------------
whitespacewhitespace
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71948&edit=1
Thread (5 messages)