Bug #80900 [NEW]: switch statement behavior inside function

From: Date: Tue, 23 Mar 2021 19:09:40 +0000
Subject: Bug #80900 [NEW]: switch statement behavior inside function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232953@lists.php.net to get a copy of this message
From:             srohde at newshour dot org
Operating system: OSX
PHP version:      7.4.16
Package:          opcache
Bug Type:         Bug
Bug description:switch statement behavior inside function

Description:
------------
When Opcache is enabled, the evaluation of a boolean variable is
inconsistent within a switch statement with a default case that is
inside of a function scope. If a variable that is assigned a boolean
value is passed, the results do not evaluate as expected, however, if a
boolean value is directly passed, the evaluation runs as expected.
Outside of a function scope, the evaluation runs as expected, regardless
of variable assignment.

Zend Engine v3.4.0
Zend OPcache v7.4.16
opcache.optimization_level 0x7FFEBFFF
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1
opcache.enable_cli=1

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

function testWithVar() {

    $booleanVar = false;

    switch ($booleanVar) {

        case 'a_test_case':
            echo 'inside testWithVar - "a_test_case"';
            break;

        default:
            echo 'inside testWithVar - "default"';
            break;

    }

}

function testWithVal() {

    switch (false) {

        case 'a_test_case':
            echo 'inside testWithVal - "a_test_case"';
            break;

        default:
            echo 'inside testWithVal - "default"';
            break;

    }

}

$booleanVar = false;

switch ($booleanVar) {

    case 'a_test_case':
        echo 'outside function - "a_test_case"';
        break;

    default:
        echo 'outside function - "default"';
        break;

}

echo PHP_EOL;

testWithVar();

echo PHP_EOL;

testWithVal();


Expected result:
----------------
outside function - "default"
inside testWithVar - "default"
inside testWithVal - "default"

Actual result:
--------------
outside function - "default"
inside testWithVar - "a_test_case"
inside testWithVal - "default"

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80900&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80900&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80900&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80900&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80900&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80900&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80900&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80900&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80900&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80900&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80900&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80900&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80900&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80900&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80900&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80900&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80900&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80900&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#232953) next »