Future::getCreatedFileAndLine
(PHP 8.6+, True Async 1.0)
public function getCreatedFileAndLine(): array
Returns information about the Future creation location as an array. Contains the file name and line number where this Future was created. Useful for debugging and tracing.
Return value
array — an array with keys file (string, file path) and line (integer, line number).
Examples
Example #1 Getting the creation location
<?php
use Async\Future;
$future = Future::completed(42); // line 5
$location = $future->getCreatedFileAndLine();
echo "File: " . $location['file'] . "\n";
echo "Line: " . $location['line'] . "\n";
// File: /app/script.php
// Line: 5
Example #2 Logging Future information
<?php
use Async\Future;
use Async\FutureState;
function createTrackedFuture(): Future {
$state = new FutureState();
$future = new Future($state);
$info = $future->getCreatedFileAndLine();
error_log(sprintf(
"Future created at %s:%d",
$info['file'],
$info['line']
));
return $future;
}
See also
- Future::getCreatedLocation — Creation location as a string
- Future::getCompletedFileAndLine — Future completion location
- Future::getAwaitingInfo — Information about waiters