php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75608 Narrowing occurred during type inference
Submitted: 2017-12-01 02:03 UTC Modified: 2018-01-09 17:48 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: anatoly dot pashin at gmail dot com Assigned: laruence (profile)
Status: Closed Package: *General Issues
PHP Version: 7.1.12 OS: centos
Private report: No CVE-ID: None
 [2017-12-01 02:03 UTC] anatoly dot pashin at gmail dot com
Description:
------------
Today we updated php to 7.1.12 and saw some errors during deploy.
Deploy algo:
1. get new files in /www/versions/795.17 directory
2. change symbolic link so it points to it
3. call php-fpm reload.

Error is thrown for some requests after 1-2 minute after reload.

You can see source of YiiBase.php at https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php

Please tell me email which I can send SpDelivery.php privately.

Test script:
---------------
System_PhpException: Uncaught exception 'System_PhpException' with message 'Narrowing occurred during type inference. Please file a bug report on bugs.php.net' in /www/versions/795.17/vendor/yiisoft/yii/framework/YiiBase.php:421
in System_Global::{closure} called at /www/versions/795.17/vendor/yiisoft/yii/framework/YiiBase.php (421)
in include called at /www/versions/795.17/vendor/yiisoft/yii/framework/YiiBase.php (421)
in YiiBase::autoload called at ? (?)
in spl_autoload_call called at /www/versions/795.17/src/DeliveryCalculator/SpDelivery.php (67)
in Sp\DeliveryCalculator\SpDelivery::detectTariffs called at /www/versions/795.17/src/DeliveryCalculator/SpDelivery.php (21)
in Sp\DeliveryCalculator\SpDelivery::getCalculation called at /www/versions/795.17/protected/models/Distributors.php (982)
in Distributors::getMinimalDeliveryCalculation called at /www/versions/795.17/protected/components/SHtml.php (1618)
in SHtml::getDeliverySummary called at /www/versions/795.17/public_html/includes/classes/Widgets/Layout.php (65)
in Widgets_Layout::getHeader called at /www/versions/795.17/public_html/includes/classes/Widgets/HtmlPage.php (213)
in Widgets_HtmlPage::printHeader called at /www/versions/795.17/public_html/ui/megaorder.php (103)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-01 10:07 UTC] laruence@php.net
the error seems not in YiiBase.php but the file which is trying to include in line 421

could you please try to figure out which file it was trying to include?

thanks
 [2017-12-01 14:05 UTC] acm at tweakers dot net
We see the same issue (with the ppa version for ubuntu, 7.1.12-1, from https://launchpad.net/~ondrej/+archive/ubuntu/php).

After stripping a class of pretty much all its functionality, we ended with this below php code. Note, the below code is actually not useful anymore. But just running 'php filename.php' triggers this warning:

PHP Warning:  Narrowing occurred during type inference. Please file a bug report on bugs.php.net in Unknown on line 0

<?php
class ReactionRatingService
{
    public function calculateBoostPoints()
    {
        while ($reaction = $reactions) {
            $reactionRatings = $this->validFunction();

            $totalWeight  = 0;
            $runningScore = 0;
            $queue        = [];
            foreach ($reactionRatings as $ratingData) {
                if ($runningScore != $reaction['Score']) {
                    if ( ! $ratingData['BoostEarned']) {
                        $queue[] = $ratingData['UserID'];
                    }
                } else {
                    foreach ($queue as $userId) {
                        $userBoostPointsRecalculate[$userId][] = $reaction['ID'];
                    }
                }
                $totalWeight += $ratingData['Weight'];
            }
        }
    }
}
 [2017-12-02 11:23 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2017-12-04 02:01 UTC] anatoly dot pashin at gmail dot com
Laruence, I know problem is not in YiiBase.php :) it tries to include SpDelivery.php, which I can't post here. If you agree to not share it, I can email it to you privately.

I can't determine which part of code in SpDelivery.php causes issue, because error  goes away from time to time when I try to edit that file. So I change any line, error gone. I change another one and it's returned.

About file acm at tweakers dot net posted: I can't reproduce it from cli (because opcache is disabled in cli). I see 'Narrowing occurred during type inference' error message when I try to open it from webroot through php-fpm. But when I press f5 to refresh page, error is gone and script is executed successfully.

PHP 7.1.12 (cli) (built: Dec  1 2017 14:08:55) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.12, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
 [2017-12-04 02:58 UTC] anatoly dot pashin at gmail dot com
Laruence, I managed to get minimal reproducible example. Following code produces warning constantly.

class DeliveryTariffs extends BaseActiveRecord
{
    public static function foo($arg1, $arg2 = null)
    {
        $a = self::someMethod();
        $b = [];
        foreach ($a as $c) {
            foreach ($b as $d => $e) {
                if (count(array_intersect($e['f'], $j['f'])) / min(count($e['f']), count($j['f'])) > 0.5) {
                    $b[$d]['g'][$h] = $j['g'][$h];
                    $i = true;
                    break;
                }
            }
            if (!$i) {
                $b[] = $j;
            }
        }

        return $b;
    }
}
 [2017-12-04 14:23 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5934bff91337b876195e9290b0811240052be7a3
Log: Fixed bug #75608 (&quot;Narrowing occurred during type inference&quot; error)
 [2017-12-04 14:23 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2017-12-04 14:40 UTC] anatoly dot pashin at gmail dot com
Sorry, Dmitry, is my code sampl ecovered too? Didn't found it in diff.
 [2018-01-08 15:24 UTC] a dot hacicheant at gmail dot com
The problem is not solved in 7.1.3 version.
I've got the same issue with PHP_CodeSniffer
https://github.com/squizlabs/PHP_CodeSniffer/issues/1785 (last comments)
 [2018-01-09 17:48 UTC] nikic@php.net
@a dot hacicheant at gmail dot com: This additional issue how now been fixed with
https://github.com/php/php-src/commit/f208187773edd9423e64b5b4dd16b146260c780d.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 15 09:01:25 2018 UTC