1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-24 15:12:22 +01:00
Files
archived-doc-ja/reference/errorfunc/functions/trigger-error.xml
Hideki Kinjyo 2d5c2712f6 [PHP 8.4] fix php/doc-en#4063 (PHP 8.4: trigger_error() updates) (#191)
* [WIP] work on php/doc-en#4063

* #191 Insert original content

ref: 72b70d7c3c

* #191 Translate

* #194 Fix element position
2024-11-25 23:05:37 +09:00

183 lines
5.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 72b70d7c3c3b2b87423641906da2db407c32c3c3 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: takagi -->
<refentry xml:id="function.trigger-error" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>trigger_error</refname>
<refpurpose>ユーザーレベルのエラー/警告/通知メッセージを生成する</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>true</type><methodname>trigger_error</methodname>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>error_level</parameter><initializer><constant>E_USER_NOTICE</constant></initializer></methodparam>
</methodsynopsis>
<para>
ユーザーエラーを発生させるために使います。組み込みのエラーハンドラまたは新しいエラーハンドラ (<function>set_error_handler</function>)
として設定済みのユーザー定義関数と組み合わせて使うこともできます。
</para>
<para>
この関数は、実行時の例外に特定の応答を生成する必要がある場合に便利です。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<para>
このエラーに割り当てられたメッセージ。長さは最大 1024 バイトまでです。1024 バイトを超える部分は切り捨てられます。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>error_level</parameter></term>
<listitem>
<para>
このエラーに割り当てられたエラー型です。<constant>E_USER_<replaceable>*</replaceable></constant> の定数のみが指定可能で、デフォルトは <constant>E_USER_NOTICE</constant> です。
</para>
<warning>
<simpara>
<parameter>error_level</parameter> として
<constant>E_USER_ERROR</constant> を指定するのは非推奨となりました。
かわりに、<exceptionname>Exception</exceptionname> をスローするか、
<function>exit</function> を呼び出してください。
</simpara>
</warning>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.true.always;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
<parameter>error_level</parameter>
<constant>E_USER_ERROR</constant>, <constant>E_USER_WARNING</constant>,
<constant>E_USER_NOTICE</constant>, <constant>E_USER_DEPRECATED</constant>
のいずれかでない場合、この関数は <classname>ValueError</classname>
をスローします。
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
<parameter>error_level</parameter> として
<constant>E_USER_ERROR</constant> を指定するのは非推奨となりました。
かわりに、<exceptionname>Exception</exceptionname> をスローするか、
<function>exit</function> を呼び出してください。
</entry>
</row>
<row>
<entry>8.4.0</entry>
<entry>
戻り値の型が、<type>bool</type> ではなく
<type>true</type> に変更されました。
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
不正な <parameter>error_level</parameter>
を指定すると、<classname>ValueError</classname> をスローするようになりました。
これより前のバージョンでは、&false; を返していました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>trigger_error</function> の例</title>
<para>
より拡張した例については <function>set_error_handler</function>
を参照ください。
</para>
<programlisting role="php">
<![CDATA[
<?php
$password = $_POST['password'] ?? '';
if ($password === '') {
trigger_error("空のパスワードを使用することは安全ではありません", E_USER_WARNING);
}
$hash = password_hash($password, PASSWORD_DEFAULT);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
<parameter>message</parameter> の HTML エンティティはエスケープされません。エラーをブラウザに表示するのであれば、メッセージに <function>htmlentities</function> を使います。
</para>
</warning>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>error_reporting</function></member>
<member><function>set_error_handler</function></member>
<member><function>restore_error_handler</function></member>
<member><link linkend="errorfunc.constants">エラーレベル定数</link></member>
<member><classname>Deprecated</classname> アトリビュート</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
-->