Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

stream context option error_mode must be of type StreamErrorMode

Description

PHP 8.6 adds a stream context option, error_mode, that controls how errors raised by a stream operation are reported. It must be one of the cases of the StreamErrorMode enum: StreamErrorMode::Error (the default, standard PHP warnings/notices), StreamErrorMode::Exception (throw a StreamException for terminating errors), or StreamErrorMode::Silent (suppress error output entirely).

Passing anything other than a StreamErrorMode case, such as a plain string, throws a TypeError when the stream operation reads the option, instead of the option being silently ignored.

Example

<?php

$context = stream_context_create([
    'stream' => ['error_mode' => 'exception'],
]);

file_get_contents('https://example.invalid/', false, $context);

?>

Literal Examples

  • stream context option ‘error_mode’ must be of type StreamErrorMode

Alternatives

  • Pass one of the StreamErrorMode enum cases, e.g. StreamErrorMode::Exception, instead of a string or other value.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See