PHP Conference Kansai 2026 (JAPAN)

stream_clear_errors

(PHP 8 >= 8.6.0)

stream_clear_errors — ストリーム操作で保持されたエラーを破棄する

説明

function stream_clear_errors(): void

stream_last_errors() が返すエラーを破棄します。

これらのエラーは、別の操作でエラーが保持されるまで残ります。 そのため、ある操作の前にエラーを破棄しておけば、 その操作でエラーが保持されたかどうかを後から判別できます。

パラメータ

この関数にはパラメータはありません。

戻り値

値を返しません。

例

例1 stream_clear_errors() の例

<?php
$context = stream_context_create([
    'stream' => [
        'error_mode' => StreamErrorMode::Silent,
    ],
]);

fopen('/nonexistent/file.txt', 'r', false, $context);
var_dump(count(stream_last_errors()));

stream_clear_errors();
var_dump(count(stream_last_errors()));

上の例の出力は以下となります。

int(1)
int(0)

参考

+add a note

User Contributed Notes

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