BitOne / php-meminfo

PHP extension to get insight about memory usage
MIT License
1.08k stars 78 forks source link

Duplication of objects with multiple references on PHP 7 #68

Closed BitOne closed 6 years ago

BitOne commented 6 years ago

From the following code:

<?php

unset($_GET);
unset($_FILES);
unset($_POST);
unset($_SERVER);
unset($_COOKIE);
unset($argv);
unset($argc);

$a = new StdClass();
$b = $a;

$b->test = "foo";

meminfo_dump(fopen('php://stdout', 'w'));

With PHP7, we get the following wrong result::

"items": {
    "0x7fc8d40571e0" : {
        "type" : "object",
        "size" : "72",
        "symbol_name" : "a",
        "is_root" : true,
        "frame" : "<GLOBAL>",
        "class" : "stdClass",
        "object_handle" : "1",
        "children" : {
            "test":"0x7fc8d405d660"
        }
    },
    "0x7fc8d405d660" : {
        "type" : "string",
        "size" : "19",
        "is_root" : false
    },
    "0x7fc8d4057200" : {
        "type" : "object",
        "size" : "72",
        "symbol_name" : "b",
        "is_root" : true,
        "frame" : "<GLOBAL>",
        "class" : "stdClass",
        "object_handle" : "1",
        "children" : {
            "test":"0x7fc8d405d660"
        }
    }
}

The object with handle 1 is duplicated for each reference.

The result with the PHP 5 version of the extension is correct:

"items": {
    "0x7f69b1095158" : {
        "type" : "object",
        "size" : "56",
        "symbol_name" : "a",
        "is_root" : true,
        "frame" : "<GLOBAL>",
        "class" : "stdClass",
        "object_handle" : "1",
        "children" : {
            "test":"0x7f69b10950f8"
        }
    },
    "0x7f69b10950f8" : {
        "type" : "string",
        "size" : "27",
        "is_root" : false
    }
}