PHP 8.5.0 Alpha 1 available for testing

Fiber::getCurrent

(PHP 8 >= 8.1.0)

Fiber::getCurrentGets the currently executing Fiber instance

Description

public static Fiber::getCurrent(): ?Fiber

Parameters

This function has no parameters.

Return Values

Returns the currently executing Fiber instance or null if this method is called from outside a fiber.

add a note

User Contributed Notes 1 note

up
0
booleantype1990 at gmail dot com
1 month ago
Fiber::getCurrent() will only return true if you call it from within a Fiber while it is running.

<?php
$fiber
= new Fiber(function () {
echo
"Inside Fiber. getCurrent: ";
var_dump(Fiber::getCurrent()); / Here is object(Fiber)#1 (0) { }

Fiber::suspend();

echo
"Inside Fiber again after resume(). getCurrent: ";
var_dump(Fiber::getCurrent()); / object(Fiber)#1 (0) { } again
});

echo
"Before Fiber launch. getCurrent: ";
var_dump($fiber->getCurrent()); / Here is NULL

$fiber->start();

echo
"After suspend. getCurrent: ";
var_dump($fiber->getCurrent()); / Here is NULL

$fiber->resume();

echo
"After resume. getCurrent: ";
var_dump($fiber->getCurrent()); / Here is NULL
?>

Result:
Before Fiber launch. getCurrent: NULL
Inside Fiber. getCurrent: object(Fiber)#1 (0) {}
After suspend. getCurrent: NULL
Inside Fiber again after resume(). getCurrent: object(Fiber)#1 (0) {}
After resume. getCurrent: NULL
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant