php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73792 invalid foreach loop hangs script
Submitted: 2016-12-20 11:54 UTC Modified: 2016-12-20 12:06 UTC
From: ryan dot brothers at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ryan dot brothers at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-20 11:54 UTC] ryan dot brothers at gmail dot com
Description:
------------
When running the below in PHP 7.1.0, the foreach loop hangs the script, and my CPU goes to 100% utilization.

If &$value is changed to $value, then it runs cleanly.


Test script:
---------------
<?php
$a = 'aaa';

foreach ($a['bbb'] as &$value)
{
	echo 'loop';
}

unset($value);

echo 'done';


Expected result:
----------------
Warning: Illegal string offset 'bbb' in /tmp/test.php on line 4

Warning: Invalid argument supplied for foreach() in /tmp/test.php on line 4
done


Actual result:
--------------
Warning: Illegal string offset 'bbb' in /tmp/test.php on line 4

then it hangs


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-20 12:06 UTC] requinix@php.net
-Status: Open +Status: Verified -PHP Version: 7.1.0 +PHP Version: 7.0
 [2016-12-20 12:06 UTC] requinix@php.net
3v4l doesn't like it since 7.0. https://3v4l.org/YhlXN

On Windows, PHP 7.0.9 crashes (not responding) but 7.1.0 gives

Warning: Illegal string offset 'bbb' in - on line 4

Fatal error: Uncaught Error: Cannot return string offsets by reference in -:4
Stack trace:
#0 {main}
  thrown in - on line 4
 [2016-12-20 13:54 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c6a2fb08cb8c0dddc16a62a816249c68132773d
Log: Fixed bug #73792 (invalid foreach loop hangs script)
 [2016-12-20 13:54 UTC] dmitry@php.net
-Status: Verified +Status: Closed
 [2016-12-20 13:55 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c6a2fb08cb8c0dddc16a62a816249c68132773d
Log: Fixed bug #73792 (invalid foreach loop hangs script)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 11:01:27 2024 UTC