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

From: Date: Wed, 09 Dec 2015 01:50:00 +0000
Subject: Bug #71067 [Opn->Fbk]: 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-197716@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71067&edit=1

 ID:                 71067
 Updated by:         laruence@php.net
 Reported by:        gal at webrats dot co dot il
 Summary:            Local object in class method stays in memory for
                     each call
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            *General Issues
 Operating System:   Centos 6.7
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

I can not reproduce this. are you meaning run your example codes from:

php7 example.php?

thanks


Previous Comments:
------------------------------------------------------------------------
[2015-12-08 22:51:46] gal at webrats dot co dot il

Description:
------------
Local object variable inside a class method is not recreated in each function call when executed
from cli.
Works properly through php-fpm but outputs a different result when executed through cli.

It does not happen without the (object) casting. Also if I'll instantiate $arr with new
stdClass() it will not happen.
Seems like the $arr = (object) is being preserved in the memory by php7's engine.

Test script:
---------------
<?php
class Test {
    public function test(){
        $arr = (object) [
            'children' => []
        ];
        $arr->children[] = 1;
        return $arr;
    }
}

$o = new Test();
$o->test();

print_r( $o->test() );

Expected result:
----------------
stdClass Object
(
    [children] => Array
        (
            [0] => 1
        )
)

Actual result:
--------------
stdClass Object
(
    [children] => Array
        (
            [0] => 1
            [1] => 1
        )
)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71067&edit=1


Thread (7 messages)

« previous php.bugs (#197716) next »