stream_clear_errors

Discards the stored stream errors

Description

void stream_clear_errors()

Discards the errors that stream_last_errors would return.

As stored errors are kept until another operation stores errors, clearing them before an operation makes it possible to tell afterwards whether that operation stored any.

Parameters

This function has no parameters.

Return Values

No value is returned.

Examples

Example #1 stream_clear_errors example

<?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()));

The above example will output:

int(1)
int(0)

See Also