Skip to content

Fiber stack variables do not participate in cycle collector #9735

@xjaja

Description

@xjaja

Description

behavior1: 3v4l
behavior2: 3v4l

The following code:

<?php
class ClassName1
{
    function __destruct() {
        print "Destroying " . __CLASS__ . "\n";
    }
}

$fiber = new Fiber(
    function() {
        $d1 = new ClassName1;

        // Resulted output
        $d2 = \WeakReference::create(\Fiber::getCurrent())->get();
        
        // Expected output
        //\WeakReference::create(\Fiber::getCurrent())->get();

        Fiber::suspend();
        return ;
    }
);
echo "1\n";
$fiber->start();

echo "2\n";
$fiber = null;

echo "3\n";

Resulted in this output:

1
2
3
Destroying ClassName1

But I expected this output instead:

1
2
Destroying ClassName1
3

PHP Version

php 8.1.11

Operating System

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions