File: declare.xml

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (208 lines) | stat: -rw-r--r-- 5,207 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 297557 $ -->

<sect1 xml:id="control-structures.declare" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <title><literal>declare</literal></title>
 <para>
  The <literal>declare</literal> construct is used to
  set execution directives for a block of code.
  The syntax of <literal>declare</literal> is similar to
  the syntax of other flow control constructs:
  <informalexample>
   <programlisting>
<![CDATA[
declare (directive)
    statement
]]>
   </programlisting>
  </informalexample>
 </para>
 <para>
  The <literal>directive</literal> section allows the
  behavior of the <literal>declare</literal> block to
  be set.
  Currently only two directives are recognized: the
  <literal>ticks</literal> directive (See below for more
  information on the
  <link linkend="control-structures.declare.ticks">ticks</link>
  directive) and the <literal>encoding</literal> directive (See below for more
  information on the
  <link linkend="control-structures.declare.encoding">encoding</link>
  directive).
 </para>
 <note>
  <simpara>
   The encoding directive was added in PHP 5.3.0
  </simpara>
 </note>
 <para>
  The <literal>statement</literal> part of the
  <literal>declare</literal> block will be executed - how
  it is executed and what side effects occur during execution
  may depend on the directive set in the
  <literal>directive</literal> block.
 </para>
 <para>
  The <literal>declare</literal> construct can also be used in the global
  scope, affecting all code following it (however if the file with
  <literal>declare</literal> was included then it does not affect the parent
  file).
  <informalexample>
   <programlisting role="php">
<![CDATA[
<?php
// these are the same:

// you can use this:
declare(ticks=1) {
    // entire script here
}

// or you can use this:
declare(ticks=1);
// entire script here
?>
]]>
   </programlisting>
  </informalexample>
 </para>

 <sect2 xml:id="control-structures.declare.ticks">
  <title>Ticks</title>
  <para>A tick is an event that occurs for every
  <varname>N</varname> low-level tickable statements executed
  by the parser within the <literal>declare</literal> block.
  The value for <varname>N</varname> is specified
  using <code>ticks=<varname>N</varname></code>
  within the <literal>declare</literal> blocks's
  <literal>directive</literal> section.
 </para>
 <para>
  Not all statements are tickable. Typically, condition
  expressions and argument expressions are not tickable.
 </para>
 <para>
  The event(s) that occur on each tick are specified using the
  <function>register_tick_function</function>. See the example
  below for more details. Note that more than one event can occur
  for each tick.
 </para>
 <para>
  <example>
   <title>Tick usage example</title>
   <programlisting role="php">
<![CDATA[
<?php

declare(ticks=1);

// A function called on each tick event
function tick_handler()
{
    echo "tick_handler() called\n";
}

register_tick_function('tick_handler');

$a = 1;

if ($a > 0) {
    $a += 2;
    print($a);
}

?>
]]>
   </programlisting>
  </example>
 </para>
 <para>
  <example>
   <title>Ticks usage example</title>
   <programlisting role="php">
<![CDATA[
<?php

function tick_handler()
{
  echo "tick_handler() called\n";
}

$a = 1;
tick_handler();

if ($a > 0) {
    $a += 2;
    tick_handler();
    print($a);
    tick_handler();
}
tick_handler();

?>
]]>
   </programlisting>
  </example>
 </para>
 <simpara>
  See also <function>register_tick_function</function> and
  <function>unregister_tick_function</function>.
 </simpara>
 </sect2>
 <sect2 xml:id="control-structures.declare.encoding">
  <title>Encoding</title>
  <para>
    A script's encoding can be specified per-script using the encoding directive.
  <example>
   <title>Declaring an encoding for the script.</title>
    <programlisting role="php">
<![CDATA[
<?php
declare(encoding='ISO-8859-1');
// code here
?>
]]>
    </programlisting>
   </example>
  </para>

  <caution>
   <simpara>
    When combined with namespaces, the only legal syntax for declare
    is <literal>declare(encoding='...');</literal> where <literal>...</literal>
    is the encoding value.  <literal>declare(encoding='...') {}</literal>
    will result in a parse error when combined with namespaces.
   </simpara>
  </caution>
  <para>
   The encoding declare value is ignored in PHP 5.3 unless php is compiled with
   <literal>--enable-zend-multibyte</literal>.
   <!-- FIXME PHP_6 
   In PHP 6.0, the <literal>encoding</literal>
   directive will be used to inform the scanner what encoding the file is created in.  Legal
   values are encoding names such as <literal>UTF-8</literal>.
   -->
  </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
-->