Coroutine::getSpawnFileAndLine

(PHP 8.6+, True Async 1.0)

public Coroutine::getSpawnFileAndLine(): array

Returns the file and line number where spawn() was called to create this coroutine.

Return Value

array – an array of two elements:

Examples

Example #1 Basic usage

<?php

use function Async\spawn;

$coroutine = spawn(fn() => "test"); // line 5

[$file, $line] = $coroutine->getSpawnFileAndLine();

echo "File: $file\n";  // /app/script.php
echo "Line: $line\n"; // 5

See Also