Bug #80900 [Ver->Csd]: switch statement behavior inside function

From: Date: Tue, 13 Apr 2021 16:30:50 +0000
Subject: Bug #80900 [Ver->Csd]: switch statement behavior inside function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233407@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80900&edit=1

 ID:                 80900
 Updated by:         git@php.net
 Reported by:        srohde at newshour dot org
 Summary:            switch statement behavior inside function
-Status:             Verified
+Status:             Closed
 Type:               Bug
 Package:            opcache
 Operating System:   OSX
 PHP Version:        7.4.16
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of twose
Revision: https://github.com/php/php-src/commit/7c6cf094631e5bea07ebbf972d2cc5c0d3611984
Log: Fixed bug #80900


Previous Comments:
------------------------------------------------------------------------
[2021-03-24 11:15:50] cmb@php.net

I can confirm this.  With optimization_level=0xA0, testWithVal()
fails as well.

------------------------------------------------------------------------
[2021-03-23 19:09:40] srohde at newshour dot org

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 this bug report at https://bugs.php.net/bug.php?id=80900&edit=1


Thread (3 messages)

« previous php.bugs (#233407) next »