Upcoming Critical PHP Security Release

stream_last_errors

(PHP 8 >= 8.6.0)

stream_last_errors — Returns the stored errors of the most recent stream operation

Description

function stream_last_errors(): array

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().

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Returns a list of StreamError objects in the order in which the errors were reported, or an empty array if no errors are stored.

Exemples

Exemple #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;
}

L'exemple ci-dessus va afficher :

bool(false)
OpenFailed: Failed to open stream: No such file or directory

Voir aussi

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top