php-meminfo icon indicating copy to clipboard operation
php-meminfo copied to clipboard

Some zvals are missing in memory dump for classes with the __debugInfo magic.

Open vtsykun opened this issue 1 year ago • 0 comments

STR

  1. Run script
<?php declare(strict_types=1);

namespace AAA;

unset($GLOBALS['_POST'], $GLOBALS['_COOKIE'], $GLOBALS['_FILES'], $GLOBALS['argv'], $GLOBALS['_GET'], $GLOBALS['_SERVER'], $GLOBALS['argc'], $GLOBALS['argv']);

class MTProtoBug
{
    private int $v = 1;
    private array $info = [];

    public function __debugInfo(): array
    {
        $vars = get_object_vars($this);
        unset($vars['info']);
        return $vars;
    }
}

$bug = new MTProtoBug();
\meminfo_dump(\fopen('/tmp/mem_dump.json', 'w'));

Actual result

{
  "header" : {
    "memory_usage" : 360456,
    "memory_usage_real" : 2097152,
    "peak_memory_usage" : 429360,
    "peak_memory_usage_real" : 2097152
  },
  "items": {
    "0x7fd6f746a140" : {
        "type" : "object",
        "size" : "72",
        "symbol_name" : "bug",
        "is_root" : true,
        "frame" : "<GLOBAL>",
        "class" : "AAA\\MTProtoBug",
        "object_handle" : "1",
        "children" : {
            "v":"0x7fd6f745ca40"
        }
    },
    "0x7fd6f745ca40" : {
        "type" : "int",
        "size" : "16",
        "is_root" : false
    }
}
}

Expect result

MTProtoBug->info must persist in the memory dump

vtsykun avatar Feb 18 '24 22:02 vtsykun