Bug #71266 [NEW]: Missing separation of properties HT in foreach etc.
| From: | nikic@php.net | Date: | Sun, 03 Jan 2016 12:08:28 +0000 |
| Subject: | Bug #71266 [NEW]: Missing separation of properties HT in foreach etc. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-198378@lists.php.net to get a copy of this message | ||
From: nikic
Operating system:
PHP version: 7.0Git-2016-01-03 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Missing separation of properties HT in foreach etc.
Description:
------------
There are currently a number of places in the engine and library where
the properties table is not properly separated. Essentially it's all the
cases where get_properties() (or OBJPROP or HASH_OF) is used in a write
context.
Two examples (assuming no immutable arrays):
$obj = (object) ['foo' => 1, 'bar' => 2];
foreach ($obj as $val) {
var_dump($val);
$obj->bar = 42;
}
This outputs 1, 1, 42 instead of 1, 42, because the properties table
will be separated at the assignment, while it should have been separated
at the start of the loop.
$arr = ['foo' => 1, 'bar' => 2];
$obj = (object) $arr;
next($obj);
var_dump(current($arr));
This outputs 2 instead of 1, because next() did not separate the
properties HT, so it is still shared with the array.
I'm not sure how we should best fix this. We could always separate in
get_properties(), however not all get_properties() uses are in write
context. We can't cleanly separate outside get_properties(), as we'd
have to assume how the properties are stored. The best option would
likely be an extra argument to determine read/write context, but that's
not ABI compatible.
--
Edit bug report at https://bugs.php.net/bug.php?id=71266&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71266&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71266&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71266&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71266&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71266&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71266&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71266&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71266&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71266&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71266&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71266&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71266&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71266&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71266&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71266&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71266&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71266&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71266&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71266&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71266&r=mysqlcfg