mirror of
https://github.com/php/doc-ja.git
synced 2026-04-29 19:13:26 +02:00
0a15f1bb57
Closes #310 Co-authored-by: KentarouTakeda <4785040+KentarouTakeda@users.noreply.github.com>
187 lines
5.8 KiB
XML
187 lines
5.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 5499acf9df7e1338d540bde207acc859792cd139 Maintainer: takagi Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
|
|
<sect1 xml:id="control-structures.declare" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>declare</title>
|
|
<?phpdoc print-version-for="declare"?>
|
|
<para>
|
|
<literal>declare</literal> 文は、あるコードブロックの中に
|
|
実行ディレクティブをセットするために使用します。<literal>declare</literal>
|
|
の文法は他の制御構造と似ています。
|
|
<informalexample>
|
|
<programlisting>
|
|
<![CDATA[
|
|
declare (ディレクティブ)
|
|
文
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
|
|
<para>
|
|
<literal>ディレクティブ</literal> の箇所で、セットされた<literal>
|
|
declare</literal>ブロックの挙動を指定することが出来ます。
|
|
現在のところ、使用できるディレクティブは以下の3つだけです:
|
|
<simplelist>
|
|
<member><link linkend="control-structures.declare.ticks"><literal>ticks</literal></link></member>
|
|
<member><link linkend="control-structures.declare.encoding"><literal>encoding</literal></link></member>
|
|
<member><link linkend="language.types.declarations.strict"><literal>strict_types</literal></link></member>
|
|
</simplelist>
|
|
</para>
|
|
|
|
<para>
|
|
ディレクティブの処理は、ファイルをコンパイルする際に行われるので、
|
|
ディレクティブの値として渡せるのは、リテラルだけとなります。
|
|
変数や定数は、使えません。以下に例を示します。
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// これは有効です
|
|
declare(ticks=1);
|
|
|
|
// これは無効です
|
|
const TICK_VALUE = 1;
|
|
declare(ticks=TICK_VALUE);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<literal>declare</literal> ブロックの <literal>文</literal>
|
|
の実行のされ方や実行時にどのような作用が起こるかについては
|
|
<literal>ディレクティブ</literal> に何が指定されたかに依存します。
|
|
</para>
|
|
<para>
|
|
<literal>declare</literal> 文はグローバルスコープとしても使用され、
|
|
それはそれ以降のコード上の全てにおいて影響します
|
|
(しかし、<literal>declare</literal> を含むファイルがインクルードされた場合は、
|
|
親ファイルにはその影響は及びません)。
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// 以下は同じ意味です
|
|
|
|
// こうすることもできますし、
|
|
declare(ticks=1) {
|
|
// ここにすべてのスクリプトを書きます
|
|
}
|
|
|
|
// こうすることもできます
|
|
declare(ticks=1);
|
|
// ここにすべてのスクリプトを書きます
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
|
|
<sect2 xml:id="control-structures.declare.ticks">
|
|
<title>Ticks</title>
|
|
<para>tickとは<literal>declare</literal>ブロックの実行中にパーサーが
|
|
<varname>N</varname>個の低レベル tick 可能な文を実行するごとに
|
|
発生するイベントのことです。<varname>N</varname>の値は
|
|
<literal>declare</literal>ブロックの<literal>ディレクティブ</literal>の箇所で
|
|
<literal>ticks=N</literal>のように
|
|
指定します。
|
|
</para>
|
|
<para>
|
|
すべての文が tick 可能なわけではありません。
|
|
たとえば条件式や引数式などは tick できません。
|
|
</para>
|
|
<para>
|
|
tickごとに発生させるイベントは<function>register_tick_function</function>
|
|
を使用して指定します。詳細は以下の例を参照ください。1回のtickで
|
|
複数のイベントが起こり得ることに注意してください。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Tick の使用例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
declare(ticks=1);
|
|
|
|
// tick イベントごとにコールされる関数
|
|
function tick_handler()
|
|
{
|
|
echo "tick_handler() called\n";
|
|
}
|
|
|
|
register_tick_function('tick_handler'); // tick イベント発生
|
|
|
|
$a = 1; // tick イベント発生
|
|
|
|
if ($a > 0) {
|
|
$a += 2; // tick イベント発生
|
|
print $a; // tick イベント発生
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<simpara>
|
|
<function>register_tick_function</function> および
|
|
<function>unregister_tick_function</function> も参照ください。
|
|
</simpara>
|
|
</sect2>
|
|
<sect2 xml:id="control-structures.declare.encoding">
|
|
<title>Encoding</title>
|
|
<para>
|
|
スクリプトのエンコーディングをスクリプトごとに指定するには
|
|
<literal>encoding</literal> ディレクティブを使用します。
|
|
<example>
|
|
<title>スクリプトのエンコーディングの宣言</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
declare(encoding='ISO-8859-1');
|
|
// ここにコードを書きます
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
|
|
<caution>
|
|
<simpara>
|
|
名前空間と組み合わせて使用する場合、使用できる形式は
|
|
<literal>declare(encoding='...');</literal> のみです。<literal>...</literal>
|
|
にエンコーディングを指定します。<literal>declare(encoding='...') {}</literal>
|
|
は、名前空間と組み合わせるとパースエラーとなります。
|
|
</simpara>
|
|
</caution>
|
|
<para>
|
|
<link linkend="ini.zend.script-encoding">zend.script_encoding</link> も参照ください。
|
|
</para>
|
|
</sect2>
|
|
</sect1>
|
|
|
|
<!-- 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
|
|
-->
|