(PHP 8 >= 8.6.0)
StreamException::getErrors — Returns the errors of the failed stream operation
Returns all errors reported by the stream operation that threw the exception, both terminating and non-terminating.
This function has no parameters.
Returns a list of StreamError objects in the order in which the errors were reported.
Example #1 StreamException::getErrors() example
<?php
$context = stream_context_create([
'stream' => [
'error_mode' => StreamErrorMode::Exception,
],
]);
try {
$stream = fopen('/nonexistent/file.txt', 'r', false, $context);
} catch (StreamException $exception) {
echo $exception->getMessage(), PHP_EOL;
foreach ($exception->getErrors() as $error) {
echo $error->wrapperName, ': ', $error->code->name, PHP_EOL;
}
}The above example will output:
Failed to open stream: No such file or directory plainfile: OpenFailed