Skip to content

var_dump() may leak dumped value #19801

Closed

Description

@arnaud-lb

Description

The following code:

$a = [
    new class {
        function __debugInfo() {
            global $b;
            $b->a = null;
            gc_collect_cycles();
            return [];
        }
    },
];

$b = new stdClass;
$b->a = &$a;

var_dump($b);

Leaks $a here:

GC_DELREF(myht);

That's because GC_DELREF() decrements its refcount to zero without freeing it. When the array is in GC roots it may still end up being freed, but in this case GC roots are empty.

If GC_DELREF() decremented its refcount to a non-zero value, this would miss a potential garbage cycle as well.

Possibly, debug_zval_dump() and var_export() have the same issue.

PHP Version

master

Operating System

No response

Activity

  1. added a commit that references this issue on Sep 16, 2025
    585e581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions