Bug #80955 [NEW]: References to elements in an array has side-affects to original array
| From: | yahya12 at outlook dot com | Date: | Thu, 15 Apr 2021 12:36:29 +0000 |
| Subject: | Bug #80955 [NEW]: References to elements in an array has side-affects to original array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-233439@lists.php.net to get a copy of this message | ||
From: yahya12 at outlook dot com
Operating system: Any
PHP version: 8.0.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:References to elements in an array has side-affects to original array
Description:
------------
There is a bug in PHP where the below code returns an unexpected value.
It looks like making references to an array or elements has side-effects
to the original array.
This is an issue that has been reported many times around 20 years ago,
but reported as "won't fix" (I believe due to performance issues).
- https://bugs.php.net/bug.php?id=20993
- https://bugs.php.net/bug.php?id=6417
- https://bugs.php.net/bug.php?id=7412
- https://bugs.php.net/bug.php?id=15025
I'm unsure if this issue has been raised recently, but would like to see
if this major bug will finally be fixed.
Also, can we at least have this documented in the official PHP docs.
Currently I can only find this mentioned in comments:
- https://www.php.net/manual/en/language.references.php#79220
- https://www.php.net/manual/en/language.references.whatdo.php#102123
- https://www.php.net/manual/en/language.references.php#79220
Test script:
---------------
$a = [['name' => 'John']];
$unusedVariable = &$a[0]; // seems to modify $a[0], so its type &array
$b = $a;
$b[0]['name'] = "Bob";
echo $a[0]['name];
Expected result:
----------------
John
Actual result:
--------------
Bob
--
Edit bug report at https://bugs.php.net/bug.php?id=80955&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80955&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80955&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80955&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80955&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80955&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80955&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80955&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80955&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80955&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80955&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80955&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80955&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80955&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80955&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80955&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80955&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80955&r=mysqlcfg