Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion reference/filter/functions/filter-has-var.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 627f933cfe6a033dccac32982cd68e7c1b86927f Maintainer: takagi Status: ready -->
<!-- EN-Revision: d5e14b9107cacb7d7257ebcf4beec48e0ea741bc Maintainer: takagi Status: ready -->
<!-- Generated by xml_proto.php v2.4. Found in /scripts directory of phpdoc. -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.filter-has-var">
<refnamediv>
Expand Down Expand Up @@ -46,6 +46,41 @@
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simpara>
<parameter>input_type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、<exceptionname>ValueError</exceptionname> をスローします。
</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>
<parameter>input_type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、
<exceptionname>ValueError</exceptionname> をスローするようになりました。
これより前のバージョンでは、&false; を返していました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down
64 changes: 63 additions & 1 deletion reference/filter/functions/filter-input-array.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 85264ba268a398c4b90c1948839d54ce688dd5cd Maintainer: mumumu Status: ready -->
<!-- EN-Revision: d5e14b9107cacb7d7257ebcf4beec48e0ea741bc Maintainer: mumumu Status: ready -->
<refentry xml:id="function.filter-input-array" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>filter_input_array</refname>
Expand Down Expand Up @@ -74,6 +74,68 @@
</simpara>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simpara>
<parameter>type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、<exceptionname>ValueError</exceptionname> をスローします。
</simpara>
<simpara>
<parameter>type</parameter> で指定された入力配列に値が入っている場合、
<parameter>options</parameter> が &array; で、&string; 以外のキーがあれば
<exceptionname>TypeError</exceptionname> を、
空のキーがあれば
<exceptionname>ValueError</exceptionname> をスローします。
</simpara>
<simpara>
PHP 8.5.0 以降、入力配列に存在するエントリに対して
<constant>FILTER_THROW_ON_FAILURE</constant> フラグを使うと、
フィルタが失敗した場合は
<exceptionname>Filter\FilterFailedException</exceptionname> を、
このフラグを <constant>FILTER_NULL_ON_FAILURE</constant> と一緒に使った場合は
<exceptionname>ValueError</exceptionname> をスローします。
</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>
<parameter>type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、
<exceptionname>ValueError</exceptionname> をスローするようになりました。
これより前のバージョンでは、入力配列に値が入っていないものとして扱われていました。
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>type</parameter> で指定された入力配列に値が入っている場合、
<parameter>options</parameter> に &string; 以外のキーがあれば
<exceptionname>TypeError</exceptionname> を、
空のキーがあれば
<exceptionname>ValueError</exceptionname> をスローするようになりました。
これより前のバージョンでは、<constant>E_WARNING</constant> が発生し、
&false; を返していました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
Expand Down
45 changes: 44 additions & 1 deletion reference/filter/functions/filter-input.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 603435cd84951fc720eded819c62ef2466d21b5c Maintainer: mumumu Status: ready -->
<!-- EN-Revision: d5e14b9107cacb7d7257ebcf4beec48e0ea741bc Maintainer: mumumu Status: ready -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="function.filter-input">
<refnamediv>
<refname>filter_input</refname>
Expand Down Expand Up @@ -65,6 +65,49 @@
</simpara>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simpara>
<parameter>type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、<exceptionname>ValueError</exceptionname> をスローします。
</simpara>
<simpara>
PHP 8.5.0 以降、<constant>FILTER_THROW_ON_FAILURE</constant> フラグを使うと、
フィルタが失敗した場合と
<parameter>var_name</parameter> 変数が設定されていない場合は
<exceptionname>Filter\FilterFailedException</exceptionname> を、
このフラグを <constant>FILTER_NULL_ON_FAILURE</constant> と一緒に使った場合は
<exceptionname>ValueError</exceptionname> をスローします。
</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>
<parameter>type</parameter> が
<constant>INPUT_<replaceable>*</replaceable></constant>
定数のいずれでもない場合、
<exceptionname>ValueError</exceptionname> をスローするようになりました。
これより前のバージョンでは、変数が設定されていないものとして扱われていました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
Expand Down
45 changes: 44 additions & 1 deletion reference/filter/functions/filter-var-array.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 85264ba268a398c4b90c1948839d54ce688dd5cd Maintainer: mumumu Status: ready -->
<!-- EN-Revision: d5e14b9107cacb7d7257ebcf4beec48e0ea741bc Maintainer: mumumu Status: ready -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.filter-var-array">
<refnamediv>
<refname>filter_var_array</refname>
Expand Down Expand Up @@ -101,6 +101,49 @@
</simpara>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simpara>
<parameter>options</parameter> が &array; で、&string; 以外のキーを含む場合は
<exceptionname>TypeError</exceptionname> を、空のキーを含む場合は
<exceptionname>ValueError</exceptionname> をスローします。
</simpara>
<simpara>
PHP 8.5.0 以降、<parameter>array</parameter> に存在するエントリに対して
<constant>FILTER_THROW_ON_FAILURE</constant> フラグを使うと、
フィルタが失敗した場合は
<exceptionname>Filter\FilterFailedException</exceptionname> を、
このフラグを <constant>FILTER_NULL_ON_FAILURE</constant> と一緒に使った場合は
<exceptionname>ValueError</exceptionname> をスローします。
</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>
<parameter>options</parameter> に &string; 以外のキーが含まれる場合は
<exceptionname>TypeError</exceptionname> を、空のキーが含まれる場合は
<exceptionname>ValueError</exceptionname> をスローするようになりました。
これより前のバージョンでは、<constant>E_WARNING</constant> が発生し、
&false; を返していました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
Expand Down
75 changes: 74 additions & 1 deletion reference/filter/functions/filter-var.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: c938838be5a7f6d2a0b0710476afb9fb2ccb6e52 Maintainer: mumumu Status: ready -->
<!-- EN-Revision: d5e14b9107cacb7d7257ebcf4beec48e0ea741bc Maintainer: mumumu Status: ready -->
<refentry xml:id="function.filter-var" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>filter_var</refname>
Expand Down Expand Up @@ -95,6 +95,17 @@
</simpara>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simpara>
PHP 8.5.0 以降、<constant>FILTER_THROW_ON_FAILURE</constant> フラグを使うと、
フィルタが失敗した場合は
<exceptionname>Filter\FilterFailedException</exceptionname> を、
このフラグを <constant>FILTER_NULL_ON_FAILURE</constant> と一緒に使った場合は
<exceptionname>ValueError</exceptionname> をスローします。
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
Expand Down Expand Up @@ -193,6 +204,68 @@ var_dump(filter_var($str, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FA
<![CDATA[
NULL
NULL
]]>
</screen>
</example>

<example>
<title>検証結果を正しく確認する例</title>
<programlisting role="php">
<![CDATA[
<?php

$value = '0';

// 間違い: 0 は有効な整数だが、false とみなされる
if (!filter_var($value, FILTER_VALIDATE_INT)) {
echo "Wrong check: '$value' rejected\n";
}

// 正しい: false と厳密に比較する
if (filter_var($value, FILTER_VALIDATE_INT) === false) {
echo "'$value' is not a valid integer\n";
} else {
echo "'$value' is a valid integer\n";
}

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Wrong check: '0' rejected
'0' is a valid integer
]]>
</screen>
</example>

<example>
<title>boolean の検証結果を確認する例</title>
<programlisting role="php">
<![CDATA[
<?php

foreach (['yes', 'no', 'maybe'] as $value) {
$result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

// ここでは false も有効な結果なので、null かどうかで判定する
if ($result === null) {
echo "'$value' is not a valid boolean\n";
} else {
echo "'$value' is ", var_export($result, true), "\n";
}
}

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
'yes' is true
'no' is false
'maybe' is not a valid boolean
]]>
</screen>
</example>
Expand Down