Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[80999] Fix count TypeError not documented #556

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions language-snippets.ent
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ currently not documented; only its argument list is available.

<!ENTITY example.outputs.71 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 7.1:</para>'>

<!ENTITY example.outputs.72 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 7.2:</para>'>

<!ENTITY example.outputs.73 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 7.3:</para>'>

<!ENTITY example.outputs.8 '<para xmlns="http://docbook.org/ns/docbook">Output of the above example in PHP 8:</para>'>
Expand Down
48 changes: 46 additions & 2 deletions reference/array/functions/count.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ $a[1] = 3;
$a[2] = 5;
var_dump(count($a));

$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
var_dump(count($b));
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
int(3)
int(3)
]]>
</screen>
</example>
</para>
<para>
<example>
<title><function>count</function> non Countable|array example (bad example - don't do this)</title>
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
<programlisting role="php">
<![CDATA[
<?php
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
Expand All @@ -102,13 +124,28 @@ var_dump(count(false));
<screen role="php">
<![CDATA[
int(3)
int(0)
int(1)
]]>
</screen>
&example.outputs.72;
<screen role="php">
<![CDATA[
int(3)

Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12 // as of PHP 7.2
Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12
int(0)

Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14 // as of PHP 7.2
Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14
int(1)
]]>
</screen>
&example.outputs.8;
<screen role="php">
<![CDATA[
int(3)

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable .. on line 12
]]>
</screen>
</example>
Expand Down Expand Up @@ -145,6 +182,13 @@ echo count($food); // output 2
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<function>count</function> will now throw <classname>TypeError</classname> on
invalid countable types passed to the <parameter>value</parameter> parameter.
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
Expand Down