Bug #76029 [NEW]: Serious regression in foreach() looping
| From: | mark dot scherer at spryker dot com | Date: | Wed, 28 Feb 2018 16:37:07 +0000 |
| Subject: | Bug #76029 [NEW]: Serious regression in foreach() looping | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214143@lists.php.net to get a copy of this message | ||
From: mark dot scherer at spryker dot com
Operating system: Linux
PHP version: 7.2.2
Package: *General Issues
Bug Type: Bug
Bug description:Serious regression in foreach() looping
Description:
------------
The recent changes in 7.2 must have introduced a major regression in
foreach() looping and variable assignment.
Test script:
---------------
// BROKEN NOW IN PHP7.2
foreach ($productAttributeKeys as $type) {
$isDefined =
$this->attributeTransferCollection->has($type);
$shouldBeTextArea = mb_strlen($value) > 255;
if ($isDefined) {
continue;
}
if ($shouldBeTextArea) {
$inputType = self::TEXT_AREA_INPUT_TYPE;
}
...
}
// FIXED WITH: Moving continue statement up
foreach ($productAttributeKeys as $type) {
$isDefined =
$this->attributeTransferCollection->has($type);
if ($isDefined) {
continue;
}
$shouldBeTextArea = (mb_strlen($value) > 255);
if ($shouldBeTextArea === true) {
$inputType = self::TEXT_AREA_INPUT_TYPE;
}
...
}
Expected result:
----------------
No notice/error on the most basic
$shouldBeTextArea = mb_strlen($value) > 255;
if ($isDefined) {
continue;
}
if ($shouldBeTextArea) {
$inputType = self::TEXT_AREA_INPUT_TYPE;
}
Actual result:
--------------
When using continue, variables that must be assigned and fine are
suddenly now throwing "Undefined variable: shouldBeTextArea" - this
worked in all PHP versions until 7.1 incl.
--
Edit bug report at https://bugs.php.net/bug.php?id=76029&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76029&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76029&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76029&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76029&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76029&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76029&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76029&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76029&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76029&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76029&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76029&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76029&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76029&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76029&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76029&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76029&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76029&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76029&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76029&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76029&r=mysqlcfg