|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-12-05 02:35 UTC] spam2 at rhsoft dot net
[2017-12-05 03:52 UTC] laruence@php.net
-Status: Open
+Status: Feedback
[2017-12-05 03:52 UTC] laruence@php.net
[2017-12-05 20:27 UTC] sam dot hemelryk at totaralearning dot com
-Status: Feedback
+Status: Closed
[2017-12-05 20:27 UTC] sam dot hemelryk at totaralearning dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
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) } }"