Bug #79495 [NEW]: PHP fails to emit notices about undefined variables in switch expression

From: Date: Sun, 19 Apr 2020 17:46:01 +0000
Subject: Bug #79495 [NEW]: PHP fails to emit notices about undefined variables in switch expression
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226671@lists.php.net to get a copy of this message
From: tandre Operating system: PHP version: Next Major Version Package: Output Control Bug Type: Bug Bug description:PHP fails to emit notices about undefined variables in switch expression Description: ------------ PHP does not emit notices in switch where the only case is the default case (or where there are no cases) This can be fixed by Zend/zend_compile.c emitting a CHECK_VAR opcode when the temporary value is IS_CV (a compiled variable such as $undefSwitch), in the cases where: - there are no case statements - if the only case statement is the default case. Noticed in https://github.com/php/php-src/pull/5371#discussion_r410947575 https://bugs.php.net/bug.php?id=52426 is related, but it's from 2010 (php 5.2), and I expect opinions have changed since then, e.g. with https://wiki.php.net/rfc/engine_warnings getting approved Test script: --------------- <?php ini_set('display_errors', 'stderr'); error_reporting(E_ALL); echo $undefVar; // This does emit a notice switch($undefSwitch) {} // This does not emit a notice switch($undefSwitch2) { default: echo "default\n";} // This does not emit a notice Expected result: ---------------- PHP should emit an undefined variable notice for the two switch statements in the test script Actual result: -------------- PHP does not emit any notices for the two switch statements in the test script, in php 5.3, 5.6, 7.0, 7.4, and 8.0-dev Apparently, it did emit notices in 5.5 - https://bugs.php.net/bug.php?id=68105 suggests that emitting notices was the expected behavior for 5.5. -- Edit bug report at https://bugs.php.net/bug.php?id=79495&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79495&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79495&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79495&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79495&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79495&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79495&r=support Expected behavior: https://bugs.php.net/fix.php?id=79495&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79495&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79495&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79495&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79495&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79495&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79495&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79495&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79495&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79495&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79495&r=mysqlcfg

« previous php.bugs (#226671) next »