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

说明

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

参数

此函数没有参数。

返回值

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

示例

示例 #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;
}

以上示例会输出:

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

参见

+添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top