php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71948 Variables by reference with goto and switch broken as of 7.0.5
Submitted: 2016-04-02 13:32 UTC Modified: 2016-04-02 17:47 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: dane dot tschi at gmail dot com Assigned:
Status: Duplicate Package: Variables related
PHP Version: 7.0.5 OS: Unix/OSX
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dane dot tschi at gmail dot com
New email:
PHP Version: OS:

 

 [2016-04-02 13:32 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-02 13:33 UTC] dane dot tschi at gmail dot com
-Summary: Variables by reference broken as of 7.0.5 +Summary: Variables by reference with goto and switch broken as of 7.0.5
 [2016-04-02 13:33 UTC] dane dot tschi at gmail dot com
Updated title
 [2016-04-02 14:28 UTC] 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 17:47 UTC] bwoebi@php.net
-Status: Open +Status: Duplicate
 [2016-04-02 17:47 UTC] bwoebi@php.net
Duplicate of #71914
 [2016-04-03 11:52 UTC] keevitaja at gmail dot com
This an example of a realworld broken code in PHP 7.0.5

It does work with 7.0.3 and 7.0.4

https://github.com/anomalylabs/streams-platform/blob/1.0/develop/src/Asset/Asset.php#L478
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC