Skip to content

Commit ff054fc

Browse files
deleugpncmb69
authored andcommitted
Fix #79111: is_numeric documentation utterly incomplete
We add information about leading and trailing whitespace. Co-authored-by: Christoph M. Becker <[email protected]> Closes GH-870.
1 parent c1f8c2e commit ff054fc

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

reference/var/functions/is-numeric.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,73 @@ NULL is NOT numeric
104104
</screen>
105105
</example>
106106
</para>
107+
108+
<para>
109+
<example>
110+
<title><function>is_numeric</function> with whitespace</title>
111+
<programlisting role="php">
112+
<![CDATA[
113+
<?php
114+
$tests = [
115+
" 42",
116+
"42 ",
117+
" 9001", // non-breaking space
118+
"9001 ", // non-breaking space
119+
];
120+
121+
foreach ($tests as $element) {
122+
if (is_numeric($element)) {
123+
echo var_export($element, true) . " is numeric", PHP_EOL;
124+
} else {
125+
echo var_export($element, true) . " is NOT numeric", PHP_EOL;
126+
}
127+
}
128+
?>
129+
]]>
130+
</programlisting>
131+
&example.outputs.8;
132+
<screen>
133+
<![CDATA[
134+
' 42' is numeric
135+
'42 ' is numeric
136+
' 9001' is NOT numeric
137+
'9001 ' is NOT numeric
138+
]]>
139+
</screen>
140+
&example.outputs.7;
141+
<screen>
142+
<![CDATA[
143+
' 42' is numeric
144+
'42 ' is NOT numeric
145+
' 9001' is NOT numeric
146+
'9001 ' is NOT numeric
147+
]]>
148+
</screen>
149+
</example>
150+
</para>
151+
</refsect1>
152+
153+
<refsect1 role="changelog">
154+
&reftitle.changelog;
155+
<informaltable>
156+
<tgroup cols="2">
157+
<thead>
158+
<row>
159+
<entry>&Version;</entry>
160+
<entry>&Description;</entry>
161+
</row>
162+
</thead>
163+
<tbody>
164+
<row>
165+
<entry>8.0.0</entry>
166+
<entry>
167+
Numeric strings ending with whitespace (<literal>"42 "</literal>) will now
168+
return &true;. Previously, &false; was return instead.
169+
</entry>
170+
</row>
171+
</tbody>
172+
</tgroup>
173+
</informaltable>
107174
</refsect1>
108175

109176
<refsect1 role="seealso">

0 commit comments

Comments
 (0)