Bug #75627 [Opn->Fbk]: Warning: Narrowing occurred during type inference with reproduction code
| From: | laruence@php.net | Date: | Tue, 05 Dec 2017 03:52:22 +0000 |
| Subject: | Bug #75627 [Opn->Fbk]: Warning: Narrowing occurred during type inference with reproduction code | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212924@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75627&edit=1
ID: 75627
Updated by: laruence@php.net
Reported by: sam dot hemelryk at totaralearning dot com
Summary: Warning: Narrowing occurred during type inference
with reproduction code
-Status: Open
+Status: Feedback
Type: Bug
Package: opcache
Operating System: OSX + Ubuntu
PHP Version: 7.1.12
Block user comment: N
Private report: N
New Comment:
Please try using this snapshot:
http://snaps.php.net/php-trunk-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
I believe this has been fixed yesterday....
Previous Comments:
------------------------------------------------------------------------
[2017-12-05 02:35:04] spam2 at rhsoft dot net
https://git.php.net/?p=php-src.git&a=search&h=HEAD&st=commit&s=Narrowing+occurred+during+type+inference
------------------------------------------------------------------------
[2017-12-05 02:32:04] sam dot hemelryk at totaralearning dot com
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 this bug report at https://bugs.php.net/bug.php?id=75627&edit=1