Upcoming Critical PHP Security Release

StreamException::getErrors

(PHP 8 >= 8.6.0)

StreamException::getErrors — Returns the errors of the failed stream operation

Опис

public function StreamException::getErrors(): array

Returns all errors reported by the stream operation that threw the exception, both terminating and non-terminating.

Параметри

У цієї функції немає параметрів.

Значення, що повертаються

Returns a list of StreamError objects in the order in which the errors were reported.

Приклади

Приклад #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;
    }
}

Поданий вище приклад виведе:

Failed to open stream: No such file or directory
plainfile: OpenFailed

Прогляньте також

+add a note

User Contributed Notes

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