mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 15:12:22 +01:00
284 lines
8.7 KiB
XML
284 lines
8.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: ada1d79de35239334b68d0120b011530e31244ff Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi,mumumu -->
|
|
<refentry xml:id="function.assert-options" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>assert_options</refname>
|
|
<refpurpose>様々な assert フラグを設定/取得する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsynopsisdiv>
|
|
&warn.deprecated.function-8-3-0;
|
|
</refsynopsisdiv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>assert_options</methodname>
|
|
<methodparam><type>int</type><parameter>option</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>value</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
種々の <function>assert</function> 制御オプションを設定したり、
|
|
単に現在の設定を調べたりします。
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
<function>assert_options</function> を使うことはお勧めできません。
|
|
&php.ini; のディレクティブ
|
|
<link linkend="ini.zend.assertions">zend.assertions</link> と
|
|
<link linkend="ini.assert.exception">assert.exception</link> を
|
|
<function>ini_set</function> や <function>ini_get</function>
|
|
で取得したり設定したりする方が望ましいです。
|
|
</simpara>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>option</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<table>
|
|
<title>assert オプション</title>
|
|
<tgroup cols="4">
|
|
<thead>
|
|
<row>
|
|
<entry>オプション</entry>
|
|
<entry>INI 設定</entry>
|
|
<entry>デフォルト値</entry>
|
|
<entry>説明</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>ASSERT_ACTIVE</entry>
|
|
<entry>assert.active</entry>
|
|
<entry>1</entry>
|
|
<entry><function>assert</function> による評価を有効にする</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ASSERT_EXCEPTION</entry>
|
|
<entry>assert.exception</entry>
|
|
<entry>1</entry>
|
|
<entry>assertion に失敗するたびに <classname>AssertionError</classname>をスローする</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ASSERT_WARNING</entry>
|
|
<entry>assert.warning</entry>
|
|
<entry>1</entry>
|
|
<entry>assertion に失敗するたびに PHP の警告を発生させる</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ASSERT_BAIL</entry>
|
|
<entry>assert.bail</entry>
|
|
<entry>0</entry>
|
|
<entry>assersion に失敗した場合に実行を終了する</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ASSERT_QUIET_EVAL</entry>
|
|
<entry>assert.quiet_eval</entry>
|
|
<entry>0</entry>
|
|
<entry>
|
|
assersion 式については error_reporting を無効にする。
|
|
PHP 8.0.0 以降では削除されています。
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ASSERT_CALLBACK</entry>
|
|
<entry>assert.callback</entry>
|
|
<entry>(&null;)</entry>
|
|
<entry>assertion に失敗した場合にコールされるコールバック</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>value</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
オプションに指定する新しい値。
|
|
</para>
|
|
<para>
|
|
<constant>ASSERT_CALLBACK</constant> 定数または <link linkend="ini.assert.callback">assert.callback</link>
|
|
に設定するコールバック関数は、次のようなシグネチャを持つべきです:
|
|
<methodsynopsis role="procedural">
|
|
<type>void</type><methodname>assert_callback</methodname>
|
|
<methodparam><type>string</type><parameter>file</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>line</parameter></methodparam>
|
|
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>assertion</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>description</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>file</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
<function>assert</function> 関数がコールされたファイル名
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>line</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
<function>assert</function> 関数がコールされた行番号
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>assertion</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
PHP 8.0.0 より前のバージョンでは、
|
|
この値は <function>assert</function> に渡された assertion でした。
|
|
但し、これは assertion が文字列として渡された場合に限られていました。
|
|
(assertion が 論理型の条件だった場合は、このパラメータは空文字列でした)。
|
|
PHP 8.0.0 以降では、このパラメータは常に &null; になります。
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>description</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
<function>assert</function> 関数に渡された説明
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<parameter>value</parameter>
|
|
に空文字列を渡すと、assertコールバックはリセットされます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
そのオプションの元の値を返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
<parameter>option</parameter> が無効なオプションの場合、
|
|
<classname>ValueError</classname> がスローされます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
<function>assert_option</function> は、推奨されなくなりました。
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
<parameter>option</parameter> が無効なオプションの場合、
|
|
<classname>ValueError</classname> がスローされるようになりました。
|
|
これより前のバージョンでは、&false; を返していました。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>assert_options</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// これは、assert に失敗した際の
|
|
// 処理を行う関数です
|
|
function assert_failure($file, $line, $assertion, $message)
|
|
{
|
|
echo "The assertion $assertion in $file on line $line has failed: $message";
|
|
}
|
|
|
|
// これがテスト関数です
|
|
function test_assert($parameter)
|
|
{
|
|
assert(is_bool($parameter));
|
|
}
|
|
|
|
// assert オプションを設定します
|
|
assert_options(ASSERT_ACTIVE, true);
|
|
assert_options(ASSERT_BAIL, true);
|
|
assert_options(ASSERT_WARNING, false);
|
|
assert_options(ASSERT_CALLBACK, 'assert_failure');
|
|
|
|
// 失敗する assert です
|
|
test_assert(1);
|
|
|
|
// ASSERT_BAIL が true なので
|
|
// 決してここには到達しません
|
|
echo 'Never reached';
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>assert</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|