Skip to content

Commit 8465ca6

Browse files
fix(mb-strlen): document invalid encoding ValueError and add shared snippets (#5418)
- Add mbstring.errors.encoding-invalid and mbstring.changelog.encoding-invalid entities to language-snippets.ent for consistent documentation - Use these entities in mb_strlen, mb_internal_encoding, and mb_encoding_aliases, replacing per-function custom prose and fixing classname -> exceptionname - Document that passing an invalid encoding to mb_strlen now throws a ValueError as of PHP 8.0.0; previously an E_WARNING was emitted and false was returned Fixes GH-1132 Co-authored-by: lcatoire <la.catoire@gmail.com>
1 parent 5a58993 commit 8465ca6

4 files changed

Lines changed: 22 additions & 29 deletions

File tree

language-snippets.ent

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,22 @@ encoding value will be used.</simpara>'>
12011201
</entry>
12021202
</row>'>
12031203

1204+
<!ENTITY mbstring.errors.encoding-invalid '<para xmlns="http://docbook.org/ns/docbook">
1205+
As of PHP 8.0.0, a <exceptionname>ValueError</exceptionname> is thrown if
1206+
<parameter>encoding</parameter> is an invalid encoding.
1207+
Prior to PHP 8.0.0, an <constant>E_WARNING</constant> was emitted instead.
1208+
</para>'>
1209+
1210+
<!ENTITY mbstring.changelog.encoding-invalid '<row xmlns="http://docbook.org/ns/docbook">
1211+
<entry>8.0.0</entry>
1212+
<entry>
1213+
Now throws a <exceptionname>ValueError</exceptionname> if
1214+
<parameter>encoding</parameter> is an invalid encoding.
1215+
Previously, an <constant>E_WARNING</constant> was emitted
1216+
and &false; was returned.
1217+
</entry>
1218+
</row>'>
1219+
12041220
<!-- mcrypt notes -->
12051221

12061222
<!ENTITY mcrypt.parameter.cipher '<simpara xmlns="http://docbook.org/ns/docbook">One of the <constant>MCRYPT_ciphername</constant> constants, or the name of the algorithm as string.</simpara>'>

reference/mbstring/functions/mb-encoding-aliases.xml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040

4141
<refsect1 role="errors">
4242
&reftitle.errors;
43-
<para>
44-
Throws a <classname>ValueError</classname> if
45-
<parameter>encoding</parameter> is unknown.
46-
</para>
43+
&mbstring.errors.encoding-invalid;
4744
</refsect1>
4845

4946
<refsect1 role="changelog">
@@ -57,14 +54,7 @@
5754
</row>
5855
</thead>
5956
<tbody>
60-
<row>
61-
<entry>8.0.0</entry>
62-
<entry>
63-
If the <parameter>encoding</parameter> is unknown, a <classname>ValueError</classname>
64-
is now thrown; previously an <constant>E_WARNING</constant> was emitted,
65-
and the function returned &false;.
66-
</entry>
67-
</row>
57+
&mbstring.changelog.encoding-invalid;
6858
</tbody>
6959
</tgroup>
7060
</informaltable>

reference/mbstring/functions/mb-internal-encoding.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@
5050

5151
<refsect1 role="errors">
5252
&reftitle.errors;
53-
<para>
54-
As of PHP 8.0.0, a <classname>ValueError</classname> is thrown if the
55-
value of <parameter>encoding</parameter> is an invalid encoding.
56-
Prior to PHP 8.0.0, a <constant>E_WARNING</constant> was emitted instead.
57-
</para>
53+
&mbstring.errors.encoding-invalid;
5854
</refsect1>
5955

6056
<refsect1 role="changelog">
@@ -69,14 +65,7 @@
6965
</thead>
7066
<tbody>
7167
&mbstring.changelog.encoding-nullable;
72-
<row>
73-
<entry>8.0.0</entry>
74-
<entry>
75-
Now throws a <classname>ValueError</classname> if
76-
<parameter>encoding</parameter> is an invalid encoding.
77-
Previously a <constant>E_WARNING</constant> was emitted instead.
78-
</entry>
79-
</row>
68+
&mbstring.changelog.encoding-invalid;
8069
</tbody>
8170
</tgroup>
8271
</informaltable>

reference/mbstring/functions/mb-strlen.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@
5252

5353
<refsect1 role="errors">
5454
&reftitle.errors;
55-
<para>
56-
If the encoding is unknown, an error of level
57-
<constant>E_WARNING</constant> is generated.
58-
</para>
55+
&mbstring.errors.encoding-invalid;
5956
</refsect1>
6057

6158
<refsect1 role="changelog">
@@ -70,6 +67,7 @@
7067
</thead>
7168
<tbody>
7269
&mbstring.changelog.encoding-nullable;
70+
&mbstring.changelog.encoding-invalid;
7371
</tbody>
7472
</tgroup>
7573
</informaltable>

0 commit comments

Comments
 (0)