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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Wed May 22 23:01:33 2019 UTC