Skip to content

Commit

Permalink
Fix #80999: count TypeError not documented
Browse files Browse the repository at this point in the history
* Add TypeError to changelog
* Update example for count to show TypeError
* Split example outputs into separate PHP versions
* Split examples into good and bad examples

Closes php/doc-en#556
  • Loading branch information
mumumu committed Apr 29, 2021
1 parent 88f5004 commit a5d754a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
4 changes: 3 additions & 1 deletion language-snippets.ent
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 9ee27f088aefb55de20529000792c4deefc0226b Maintainer: takagi Status: working -->
<!-- EN-Revision: a7663ad05e1a825c2ca61810a9b8d45e940a2afc Maintainer: takagi Status: working -->
<!-- Credits: hirokawa,haruki,shimooka,mumumu -->

<!ENTITY installation.enabled.disable 'この拡張モジュールはデフォルトで有効になっています。無効にしたい場合は、次のオプションを指定してコンパイルします。'>
Expand Down Expand Up @@ -508,6 +508,8 @@ PHP では、<literal>https://</literal> ラッパーでストリームをオー

<!ENTITY example.outputs.71 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 7.1 での出力は、このようになります。</para>'>

<!ENTITY example.outputs.72 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 7.2 での出力は、このようになります。</para>'>

<!ENTITY example.outputs.73 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 7.3 での出力は、このようになります。</para>'>

<!ENTITY example.outputs.8 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 8 での出力は、このようになります。:</para>'>
Expand Down
52 changes: 48 additions & 4 deletions reference/array/functions/count.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: hirokawa Status: ready -->
<!-- EN-Revision: a7663ad05e1a825c2ca61810a9b8d45e940a2afc Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka,mumumu -->
<refentry xml:id="function.count" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -88,6 +88,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>Countable|array でない値を渡した場合の <function>count</function> の例 (悪い例です - 真似しないでね!)</title>
<programlisting role="php">
<![CDATA[
<?php
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
Expand All @@ -103,13 +125,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 All @@ -135,7 +172,6 @@ echo count($food); // output 2
</example>
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
Expand All @@ -147,6 +183,14 @@ echo count($food); // output 2
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>value</parameter>
引数に不正な countable 型を渡した場合に、
<classname>TypeError</classname> をスローするようになりました。
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
Expand Down

0 comments on commit a5d754a

Please sign in to comment.