Bug #76466 [Opn]: Loop variable confusion

From: Date: Wed, 13 Jun 2018 13:17:42 +0000
Subject: Bug #76466 [Opn]: Loop variable confusion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215685@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76466&edit=1 ID: 76466 Updated by: cmb@php.net Reported by: cmb@php.net Summary: Loop variable confusion Status: Open Type: Bug Package: opcache Operating System: Linux -PHP Version: master-Git-2018-06-13 (Git) +PHP Version: 7.3.0alpha1 Block user comment: N Private report: N New Comment: Looks like the SCCP is too aggressive as of commit ce3dbb5[1]. For what it's worth, removing the if statement from the test script gives expected results. [1] <https://github.com/php/php-src/commit/ce3dbb53a7dcef314bba1d355f049ddb2252fad1> Previous Comments: ------------------------------------------------------------------------ [2018-06-13 10:38:20] cmb@php.net Related To: Bug #76446 ------------------------------------------------------------------------ [2018-06-13 10:36:10] cmb@php.net Description: ------------ Running the test script without Opcache works fine, but with Opcache enabled it results in erroneous behavior (at least after a few tries). PHP-7.2 does not exhibit this bug. Test script: --------------- <?php function foo() { for ($i = 1; $i <= 2; $i++) { if ($i == 2) { $type = 'text'; } else { $type = 'varchar'; } $field_array[] = ['name' => "pal_field{$i}", 'type' => $type, 'length' => 255, 'unsigned' => 1]; } var_dump($field_array); } foo(); Expected result: ---------------- array(2) { [0]=> array(4) { ["name"]=> string(10) "pal_field1" ["type"]=> string(7) "varchar" ["length"]=> int(255) ["unsigned"]=> int(1) } [1]=> array(4) { ["name"]=> string(10) "pal_field2" ["type"]=> string(4) "text" ["length"]=> int(255) ["unsigned"]=> int(1) } } Actual result: -------------- array(2) { [0]=> array(4) { ["name"]=> string(10) "pal_field1" ["type"]=> string(7) "varchar" ["length"]=> int(255) ["unsigned"]=> int(1) } [1]=> array(4) { ["name"]=> string(10) "pal_field1" ["type"]=> string(7) "varchar" ["length"]=> int(255) ["unsigned"]=> int(1) } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76466&edit=1

« previous php.bugs (#215685) next »