(PHP 8 >= 8.6.0)
stream_last_errors — Returns the stored errors of the most recent stream operation
Returns the errors that were stored by the most recent stream operation
that stored any. Which errors an operation stores is controlled by the
error_store
and
error_mode
stream context options. With the default options no errors are stored.
The stored errors are replaced when a later operation stores errors. They are kept when a later operation succeeds or does not store its errors, and can be discarded with stream_clear_errors().
Esta função não possui parâmetros.
Returns a list of StreamError objects in the order in which the errors were reported, or an empty array if no errors are stored.
Exemplo #1 stream_last_errors() example
<?php
$context = stream_context_create([
'stream' => [
'error_mode' => StreamErrorMode::Silent,
],
]);
$stream = fopen('/nonexistent/file.txt', 'r', false, $context);
var_dump($stream);
foreach (stream_last_errors() as $error) {
echo $error->code->name, ': ', $error->message, PHP_EOL;
}O exemplo acima produzirá:
bool(false) OpenFailed: Failed to open stream: No such file or directory