Bug #72219 [Opn]: Local object in class method stays in memory for each call
Edit report at https://bugs.php.net/bug.php?id=72219&edit=1
ID: 72219
Updated by: nikic@php.net
Reported by: jaswsinc at wsharks dot com
Summary: Local object in class method stays in memory for
each call
Status: Open
Type: Bug
Package: *General Issues
Operating System: Ubuntu 14.04 LTS
PHP Version: 7.0.6
Block user comment: N
Private report: N
New Comment:
This is probably caused by bug #71266. The object HT is not separated before iteration.
Previous Comments:
------------------------------------------------------------------------
[2016-05-15 17:03:04] jaswsinc at wsharks dot com
Description:
------------
This is almost the exact same issue seen here: https://bugs.php.net/bug.php?id=71067
That bug got zapped, but I am still able to reproduce the same issue whenever I use
foreach() by reference. The object remains cached in memory.
Test script:
---------------
<?php
class Example
{
protected $property;
public function __construct()
{
$test = (object) ['property' => 0];
print_r($test); // Expecting property=0.
foreach ($test as $_property => &$_value) {
$this->{$_property} = &$_value;
$this->{$_property} = 1;
} unset($_value);
}
}
new Example();
new Example();
Expected result:
----------------
stdClass Object
(
[property] => 0
)
stdClass Object
(
[property] => 0
)
Actual result:
--------------
stdClass Object
(
[property] => 0
)
stdClass Object
(
[property] => 1
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72219&edit=1
Thread (3 messages)