|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81254 PHP8.1: undefined method Fiber::this()
Submitted: 2021-07-12 21:04 UTC Modified: 2021-07-12 21:54 UTC
From: rainer dot jung at kippdata dot de Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 8.1.0alpha3 OS: Linux, Solaris Sparc
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: rainer dot jung at kippdata dot de
New email:
PHP Version: OS:


 [2021-07-12 21:04 UTC] rainer dot jung at kippdata dot de
I tried the second example from

The script fails, details see below.

Test script:
class EventLoop
    private string $nextId = 'a';
    private array $deferCallbacks = [];
    private array $read = [];
    private array $streamCallbacks = [];

    public function run(): void
        while (!empty($this->deferCallbacks) || !empty($this->read)) {
            $defers = $this->deferCallbacks;
            $this->deferCallbacks = [];
            foreach ($defers as $id => $defer) {


    private function select(array $read): void
        $timeout = empty($this->deferCallbacks) ? null : 0;
        if (!stream_select($read, $write, $except, $timeout, $timeout)) {

        foreach ($read as $id => $resource) {
            $callback = $this->streamCallbacks[$id];
            unset($this->read[$id], $this->streamCallbacks[$id]);

    public function defer(callable $callback): void
        $id = $this->nextId++;
        $this->deferCallbacks[$id] = $callback;

    public function read($resource, callable $callback): void
        $id = $this->nextId++;
        $this->read[$id] = $resource;
        $this->streamCallbacks[$id] = $callback;

[$read, $write] = stream_socket_pair(
    stripos(PHP_OS, 'win') === 0 ? STREAM_PF_INET : STREAM_PF_UNIX,

// Set streams to non-blocking mode.
stream_set_blocking($read, false);
stream_set_blocking($write, false);

$loop = new EventLoop;

// Read data in a separate fiber after checking if the stream is readable.
$fiber = new Fiber(function () use ($loop, $read): void {
    echo "Waiting for data...\n";

    $fiber = Fiber::this();
    $loop->read($read, fn() => $fiber->resume());

    $data = fread($read, 8192);

    echo "Received data: ", $data, "\n";

// Start the fiber, which will suspend while waiting for a read event.

// Defer writing data to an event loop callback.
$loop->defer(fn() => fwrite($write, "Hello, world!"));

// Run the event loop.

Expected result:
From the RFS:

Waiting for data...
Received data: Hello, world!

Actual result:
/path/to/bin/php fiber.php

Waiting for data...

Fatal error: Uncaught Error: Call to undefined method Fiber::this() in /var/tmp/fiber.php:66
Stack trace:
#0 [internal function]: {closure}()
#1 /var/tmp/fiber.php(76): Fiber->start()
#2 {main}
  thrown in /var/tmp/fiber.php on line 66


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-12 21:07 UTC] rainer dot jung at kippdata dot de
-Status: Open +Status: Closed
 [2021-07-12 21:07 UTC] rainer dot jung at kippdata dot de
Sorry, my bad: I now saw on php internals, that Fiber::this() got renamed to Fiber::getCurrent(). The corrected script works.
 [2021-07-12 21:54 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 06:01:31 2024 UTC