Bug #75627 [NEW]: Warning: Narrowing occurred during type inference with reproduction code

From: Date: Tue, 05 Dec 2017 02:32:07 +0000
Subject: Bug #75627 [NEW]: Warning: Narrowing occurred during type inference with reproduction code
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212921@lists.php.net to get a copy of this message
From: sam dot hemelryk at totaralearning dot com Operating system: OSX + Ubuntu PHP version: 7.1.12 Package: opcache Bug Type: Bug Bug description:Warning: Narrowing occurred during type inference with reproduction code Description: ------------ Several developers upgraded to the latest PHP 7.1.12, and PHP 7.2.0 releases in the last two days and all have encountered the following warning while trying to use our product: Warning: Narrowing occurred during type inference. Please file a bug report on bugs.php.net Our code base is very large so rather than try to share the file that generates the warning I produced a simplification of the code that causes the issue, and which can be used to reliably reproduce the issue. Please see the provided test script code. To reproduce this: * Place the test script into your web root * Start watching the server logs or config php to display warnings etc * Visit the script in your browser We've tested on several versions of PHP and the following is our findings: * OSX + PHP 7.2.0 === affected * OSX + PHP 7.1.12 === affected * OSX + PHP 7.1.12RC5 === fine * OSX + PHP 7.1.11 === fine * Ubuntu + PHP 7.2.0 === affected * Ubuntu + PHP 7.1.12 === affected Test script: --------------- <?php opcache_reset(); function test($capability) { $needed = []; $caps = (array)$capability; foreach ($caps as $cap) { if ($cap == 1) { unset($needed[$cap][1]); } else if (true) { $needed[$cap][1] = true; } } } Expected result: ---------------- Importantly no warnings. Actual result: -------------- Warning: Narrowing occurred during type inference. Please file a bug report on bugs.php.net in Unknown on line 0 The effect this has in our code base is that during execution the $needed array will magically become null *most* of the time. Once in a while it will correctly To see this effect change the test script as follows: <code> <?php opcache_reset(); function test($capability) { $needed = []; $caps = (array)$capability; foreach ($caps as $cap) { if ($cap == 1) { unset($needed[$cap][1]); } else if (true) { $needed[$cap][1] = true; } } var_dump($needed); } $test = new stdClass(); $test->a = 1; $test->b = 2; test($test); </code> Now when you call it most of the time it will output the warning and null. *Occasionally* you will not get the warning, and you will get: "array(1) { [2]=> array(1) { [1]=> bool(true) } }" -- Edit bug report at https://bugs.php.net/bug.php?id=75627&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75627&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75627&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75627&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75627&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75627&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75627&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75627&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75627&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75627&r=support Expected behavior: https://bugs.php.net/fix.php?id=75627&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75627&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75627&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75627&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75627&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75627&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75627&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75627&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75627&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75627&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75627&r=mysqlcfg

« previous php.bugs (#212921) next »