Bug #72219 [Opn->Dup]: Local object in class method stays in memory for each call

From: Date: Sat, 30 Jul 2016 12:56:07 +0000
Subject: Bug #72219 [Opn->Dup]: Local object in class method stays in memory for each call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202725@lists.php.net to get a copy of this message
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
+Status:             Duplicate
 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:

As per previous comment, this is a duplicate of bug bug #71266, which has been fixed in PHP 7.1 (not
sure if this will be backported).


Previous Comments:
------------------------------------------------------------------------
[2016-05-15 18:38:43] nikic@php.net

This is probably caused by bug #71266. The object HT is not separated before iteration.

------------------------------------------------------------------------
[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)

« previous php.bugs (#202725) next »