[doc-en] master: stream: document the errors of the stream_context_*() and stream filter functions (#6091)
| From: | Asish Kumar via GitHub | Date: | Mon, 16 Nov 2026 08:45:21 +0000 |
| Subject: | [doc-en] master: stream: document the errors of the stream_context_*() and stream filter functions (#6091) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23962@lists.php.net to get a copy of this message | ||
Author: Asish Kumar (officialasishkumar)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-16T09:45:17+01:00
Commit: https://github.com/php/doc-en/commit/e01174bde78948fb9cdc50933039754ccade11aa
Raw diff: https://github.com/php/doc-en/commit/e01174bde78948fb9cdc50933039754ccade11aa.diff
stream: document the errors of the stream_context_*() and stream filter functions (#6091)
* stream: document the errors of the context and filter functions
None of the stream_context_*() pages, nor stream_filter_register(),
stream_filter_append() and stream_filter_prepend(), had an Errors
section, although they throw since PHP 8.0 where they used to raise an
E_WARNING. This adds the Errors section and the matching changelog rows
(see ext/standard/streamsfuncs.c and ext/standard/user_filters.c):
- stream_context_get_options(), stream_context_get_params(),
stream_context_set_option(), stream_context_set_options() and
stream_context_set_params() throw a TypeError if the stream or context
is not valid (8.0.0; previously E_WARNING and false).
- Every function taking context options throws a ValueError if they are
not of the form $arr['wrapper']['option'] = $value (8.0.0).
- stream_context_create() and stream_context_set_params() throw a
TypeError if the "options" parameter is not an array (8.0.0), or if
the "notification" parameter is not a valid callback (8.5.0).
- stream_context_set_option() throws a ValueError if option_name or
value is missing for a wrapper name, or given with an options array.
- stream_context_set_default() throws a ValueError if the stream error
handling options are set on the default context (8.6.0).
- stream_filter_register() throws a ValueError for an empty filter name
(8.0.0), and as of 8.6.0 a TypeError if the class does not exist and
a ValueError if it cannot be instantiated.
- stream_filter_append() and stream_filter_prepend() emit an E_WARNING
if the filter cannot be located or created, and throw a TypeError if
the stream is not an open stream (8.0.0). Their return value no
longer claims false is returned for an invalid stream.
Checked against php-src from php-7.4.33 to the PHP-8.6 branch, and by
running each case on PHP 7.4, 8.0, 8.4, 8.5 and 8.6.0RC7.
Fixes #6082
* stream: address review feedback on context and filter error docs
* Update reference/stream/functions/stream-context-set-option.xml
---------
Co-authored-by: Louis-Arnaud <la.catoire@gmail.com>
Changed paths:
M reference/stream/functions/stream-context-create.xml
M reference/stream/functions/stream-context-get-default.xml
M reference/stream/functions/stream-context-get-options.xml
M reference/stream/functions/stream-context-get-params.xml
M reference/stream/functions/stream-context-set-default.xml
M reference/stream/functions/stream-context-set-option.xml
M reference/stream/functions/stream-context-set-options.xml
M reference/stream/functions/stream-context-set-params.xml
M reference/stream/functions/stream-filter-append.xml
M reference/stream/functions/stream-filter-prepend.xml
M reference/stream/functions/stream-filter-register.xml
Diff:
diff --git a/reference/stream/functions/stream-context-create.xml
b/reference/stream/functions/stream-context-create.xml
index 83d15668cb85..d8ae67e003af 100644
--- a/reference/stream/functions/stream-context-create.xml
+++ b/reference/stream/functions/stream-context-create.xml
@@ -56,6 +56,27 @@
</para>
</refsect1>
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter>, or the <literal>options</literal> entry
of
+ <parameter>params</parameter>, is not of the form
+ <literal>$arr['wrapper']['option'] = $value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>options</literal> entry of <parameter>params</parameter>
+ is not an array.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>notification</literal> entry of <parameter>params</parameter>
+ is not a valid callback.
+ </simpara>
+ </refsect1>
+
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
@@ -67,12 +88,32 @@
</row>
</thead>
<tbody>
+ <row>
+ <entry>8.5.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>notification</literal> entry of
<parameter>params</parameter>
+ is not a valid callback.
+ </entry>
+ </row>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>options</parameter> and <parameter>params</parameter> are
now nullable.
</entry>
</row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter>, or the <literal>options</literal>
entry of
+ <parameter>params</parameter>, is not of the expected form,
+ and a <exceptionname>TypeError</exceptionname> if the
+ <literal>options</literal> entry of <parameter>params</parameter>
+ is not an array.
+ Previously, an <constant>E_WARNING</constant> was raised.
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
diff --git a/reference/stream/functions/stream-context-get-default.xml
b/reference/stream/functions/stream-context-get-default.xml
index e637434fad54..11f9114e9a5f 100644
--- a/reference/stream/functions/stream-context-get-default.xml
+++ b/reference/stream/functions/stream-context-get-default.xml
@@ -46,6 +46,16 @@
</para>
</refsect1>
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the form
+ <literal>$arr['wrapper']['option'] = $value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ </refsect1>
+
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
@@ -63,6 +73,14 @@
<parameter>options</parameter> is now nullable.
</entry>
</row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the expected form.
+ Previously, an <constant>E_WARNING</constant> was raised.
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
diff --git a/reference/stream/functions/stream-context-get-options.xml
b/reference/stream/functions/stream-context-get-options.xml
index f765d4f73112..81c661940dd8 100644
--- a/reference/stream/functions/stream-context-get-options.xml
+++ b/reference/stream/functions/stream-context-get-options.xml
@@ -39,6 +39,40 @@
Returns an associative array with the options.
</para>
</refsect1><!-- }}} -->
+
+ <refsect1 role="errors"><!-- {{{ -->
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream_or_context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ </simpara>
+ </refsect1><!-- }}} -->
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream_or_context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
<refsect1 role="examples"><!-- {{{ -->
&reftitle.examples;
diff --git a/reference/stream/functions/stream-context-get-params.xml
b/reference/stream/functions/stream-context-get-params.xml
index 13003dc72f1f..6c5c8a3d3afa 100644
--- a/reference/stream/functions/stream-context-get-params.xml
+++ b/reference/stream/functions/stream-context-get-params.xml
@@ -41,6 +41,40 @@
</para>
</refsect1>
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
+
<refsect1 role="examples">
&reftitle.examples;
<para>
diff --git a/reference/stream/functions/stream-context-set-default.xml
b/reference/stream/functions/stream-context-set-default.xml
index 08dfe1bd3fd0..3fae14577840 100644
--- a/reference/stream/functions/stream-context-set-default.xml
+++ b/reference/stream/functions/stream-context-set-default.xml
@@ -49,6 +49,40 @@
Returns the default stream context.
</para>
</refsect1><!-- }}} -->
+
+ <refsect1 role="errors"><!-- {{{ -->
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the form
+ <literal>$arr['wrapper']['option'] = $value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ </refsect1><!-- }}} -->
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the expected form.
+ Previously, an <constant>E_WARNING</constant> was raised.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
<refsect1 role="examples"><!-- {{{ -->
&reftitle.examples;
diff --git a/reference/stream/functions/stream-context-set-option.xml
b/reference/stream/functions/stream-context-set-option.xml
index 268dec33e224..ee1c207d9ba6 100644
--- a/reference/stream/functions/stream-context-set-option.xml
+++ b/reference/stream/functions/stream-context-set-option.xml
@@ -98,6 +98,27 @@
</para>
</refsect1><!-- }}} -->
+ <refsect1 role="errors"><!-- {{{ -->
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream_or_context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>option_name</parameter> or <parameter>value</parameter>
+ is missing when <parameter>wrapper</parameter> is a string, or if either
+ of them is given along with an <parameter>options</parameter> array.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the form
+ <literal>$arr['wrapper']['option'] = $value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ </refsect1><!-- }}} -->
+
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
@@ -116,6 +137,44 @@
Use <function>stream_context_set_options</function> instead.
</entry>
</row>
+ <row>
+ <entry>8.0.9</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>value</parameter> is not provided when
+ <parameter>wrapper</parameter> is a string.
+ </entry>
+ </row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream_or_context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the expected form.
+ Previously, an <constant>E_WARNING</constant> was raised.
+ </entry>
+ </row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>option_name</parameter> is &null; when
+ <parameter>wrapper</parameter> is a string, or if
+ <parameter>option_name</parameter> or <parameter>value</parameter>
+ is given along with an <parameter>options</parameter> array.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned,
+ except when <parameter>option_name</parameter> was &null; and
+ <parameter>value</parameter> was given, which was accepted.
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
diff --git a/reference/stream/functions/stream-context-set-options.xml
b/reference/stream/functions/stream-context-set-options.xml
index d2a9f3d07017..5579bb715eb3 100644
--- a/reference/stream/functions/stream-context-set-options.xml
+++ b/reference/stream/functions/stream-context-set-options.xml
@@ -59,6 +59,21 @@
</para>
</refsect1>
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>options</parameter> is not of the form
+ <literal>$arr['wrapper']['option'] = $value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ </refsect1>
+
<refsect1 role="examples">
&reftitle.examples;
<para>
diff --git a/reference/stream/functions/stream-context-set-params.xml
b/reference/stream/functions/stream-context-set-params.xml
index 6469ca08f40f..d320d95aa81d 100644
--- a/reference/stream/functions/stream-context-set-params.xml
+++ b/reference/stream/functions/stream-context-set-params.xml
@@ -80,6 +80,74 @@
&return.success;
</para>
</refsect1><!-- }}} -->
+
+ <refsect1 role="errors"><!-- {{{ -->
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if the
+ <literal>options</literal> entry of <parameter>params</parameter>
+ is not of the form <literal>$arr['wrapper']['option'] =
$value</literal>,
+ that is, if one of its elements is not an array or has an integer key.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>options</literal> entry of <parameter>params</parameter>
+ is not an array.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>notification</literal> entry of <parameter>params</parameter>
+ is not a valid callback.
+ </simpara>
+ </refsect1><!-- }}} -->
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.5.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if the
+ <literal>notification</literal> entry of
<parameter>params</parameter>
+ is not a valid callback.
+ </entry>
+ </row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>context</parameter> is not a valid stream or
+ stream context <type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if the
+ <literal>options</literal> entry of <parameter>params</parameter>
+ is not of the expected form, and a <exceptionname>TypeError</exceptionname>
+ if it is not an array.
+ Previously, an <constant>E_WARNING</constant> was raised.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
<refsect1 role="seealso"><!-- {{{ -->
&reftitle.seealso;
diff --git a/reference/stream/functions/stream-filter-append.xml
b/reference/stream/functions/stream-filter-append.xml
index 15a096367ac3..55c57ca4cfe4 100644
--- a/reference/stream/functions/stream-filter-append.xml
+++ b/reference/stream/functions/stream-filter-append.xml
@@ -82,10 +82,43 @@
<function>stream_filter_remove</function>.
</para>
- <para>
- &false; is returned if <parameter>stream</parameter> is not a resource or
- if <parameter>filter_name</parameter> cannot be located.
- </para>
+ <simpara>
+ &false; is returned, and an <constant>E_WARNING</constant> is emitted, if
+ <parameter>filter_name</parameter> cannot be located or the filter cannot be
+ created.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream</parameter> is not an open stream
<type>resource</type>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream</parameter> is not an open stream
<type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
</refsect1>
<refsect1 role="examples">
diff --git a/reference/stream/functions/stream-filter-prepend.xml
b/reference/stream/functions/stream-filter-prepend.xml
index cfef69cc9225..64a1fdd77d07 100644
--- a/reference/stream/functions/stream-filter-prepend.xml
+++ b/reference/stream/functions/stream-filter-prepend.xml
@@ -83,10 +83,43 @@
<function>stream_filter_remove</function>.
</para>
- <para>
- &false; is returned if <parameter>stream</parameter> is not a resource or
- if <parameter>filter_name</parameter> cannot be located.
- </para>
+ <simpara>
+ &false; is returned, and an <constant>E_WARNING</constant> is emitted, if
+ <parameter>filter_name</parameter> cannot be located or the filter cannot be
+ created.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream</parameter> is not an open stream
<type>resource</type>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream</parameter> is not an open stream
<type>resource</type>.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
</refsect1>
<refsect1 role="notes">
diff --git a/reference/stream/functions/stream-filter-register.xml
b/reference/stream/functions/stream-filter-register.xml
index 5b5c71c05541..e486c7703c38 100644
--- a/reference/stream/functions/stream-filter-register.xml
+++ b/reference/stream/functions/stream-filter-register.xml
@@ -61,6 +61,39 @@
<parameter>filter_name</parameter> is already defined.
</para>
</refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>filter_name</parameter> or <parameter>class</parameter> is
empty.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ Now throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>filter_name</parameter> or <parameter>class</parameter>
+ is empty.
+ Previously, an <constant>E_WARNING</constant> was raised and &false; was
returned.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
<refsect1 role="examples">
&reftitle.examples;