php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71975 Passing by reference vs. switch
Submitted: 2016-04-06 11:22 UTC Modified: 2016-04-07 06:18 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: deem at deem dot ru Assigned:
Status: Duplicate Package: Variables related
PHP Version: 7.0.5 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: deem at deem dot ru
New email:
PHP Version: OS:

 

 [2016-04-06 11:22 UTC] deem at deem dot ru
Description:
------------
When variable passed by reference is used in switch() it becomes local for that scope

Test script:
---------------
<?php

function bug( &$var ) {
    switch( $var ) {
        case 1: $var = 2;
    }
}

function workaround( &$var ) {
    $val_local = $var;
    switch( $val_local ) {
        case 1: $var = 2;
    }
}

$var = 1; bug( $var ); echo $var , PHP_EOL;
$var = 1; workaround( $var ); echo $var , PHP_EOL;

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-07 06:18 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-04-07 06:18 UTC] nikic@php.net
Duplicate of bug #71914 (fixed in PHP 7.0.6).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC