shlomi Sat Jan 26 10:49:38 2002 EDT
Added files:
/phpdoc/he/language control-structures.xml
Log:
initial translation
Index: phpdoc/he/language/control-structures.xml
+++ phpdoc/he/language/control-structures.xml
<?xml version="1.0" encoding="iso-8859-8-i"?>
<!-- $Revision: 1.1 $ -->
<chapter id="control-structures">
<title>����-����</title>
<simpara>
�� ������ PHP ���� ���� �� ������. ����� ����� �����
����� ����, ����� ��������, �����, ������ �� ����� �����
��� ��� ��� (����� ����). ������ �������� ���-��� ��������� ';'.
�����, ���� ���� ����� �� ������ ����� �� ������ �����
������� �������� ��� ����� ������ ����� ����� ������ ���.
���� �� ������� ���� ������ �����.
</simpara>
<sect1 id="control-structures.if">
<title><literal>if</literal></title>
<para>
���� ����� �- <literal>if</literal> ��� ��� ������ �������
����� ����� ���� ����� ����� PHP. ����� �� ������ ������
�� ���� ���� ���. ���� ����� <literal>if</literal> �- PHP
���� ����� if ���� C:
<informalexample>
<programlisting>
<![CDATA[
if (expr)
statement
]]>
</programlisting>
</informalexample>
</para>
<simpara>
������ ����� �� <link linkend="language.expressions">�������</link>,
<replaceable>expr</replaceable> ����� ����� �������. ��
<replaceable>expr</replaceable> ����� �- &true;, PHP ���� ��
<replaceable>statement</replaceable>, ��� ������ ����� �- &true;, ��
����� �� �����. ���� ���� ����� - ���� ����� ������� ���� � &false;
���� ����� ����� <link
linkend="language.types.boolean.casting">'���� ���� ������'</link>.
</simpara>
<para>
������ ���� ����� <computeroutput>a is bigger than b
</computeroutput> �� <replaceable>$a</replaceable> ���� �-
<replaceable>$b</replaceable>:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($a > $b)
print "a is bigger than b";
]]>
</programlisting>
</informalexample>
</para>
<para>
������ ���� ��������� ����� ���� ������ ����� ������. �����,
��� ���� ������ �� ����� ����� ����� <literal>if</literal>.
���� ���� ����� ����� ������. ������, ������� ��� �����
<computeroutput>a is bigger than b</computeroutput> ��
<replaceable>$a</replaceable>
���� �- <replaceable>$b</replaceable>, ����� ���� �� <replaceable>$a</replaceable>
���� ������ <replaceable>$b</replaceable>:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
]]>
</programlisting>
</informalexample>
</para>
<simpara>
����� �� ����� ����� ������ ���� ����� <literal>if</literal> �����.
��� ������ ������ ��� ������� ���� ������ ����.
</simpara>
</sect1>
<sect1 id="control-structures.else">
<title><literal>else</literal></title>
<para>
������ ���� ����� ����� �� ���� ������ ������ ����� ���� �� ��.
��� �� ���� � <literal>else</literal>. <literal>else</literal>
����� ����� <literal>if</literal> ��� ���� ���� �� ������ �����
����� �� ������ ����� <literal>if</literal> ����� ���� � &false;.
������, ������� ��� ����� <computeroutput>a is bigger than
b</computeroutput> �� ���� �� <replaceable>$a</replaceable> ����
����� �� <replaceable>$b</replaceable>, �� �����
<computeroutput>a is NOT bigger than b</computeroutput> ��� ���� ���:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($a > $b) {
print "a is bigger than b";
} else {
print "a is NOT bigger than b";
}
]]>
</programlisting>
</informalexample>
����� �- <literal>else</literal> ����� �� ��� ��
����� �- <literal>if</literal> ���� ����� �- &false;, ���
����� ������ <literal>elseif</literal> �� ��.
(��� � <link
linkend="control-structures.elseif">elseif</link>).
</para>
</sect1>
<sect1 id="control-structures.elseif">
<title><literal>elseif</literal></title>
<para>
<literal>elseif</literal>, ��� ���� ����, ��� ����� ��� <literal>if</literal>
���� <literal>else</literal>. ��� ������ �� ���� � <literal>if</literal> ���
����� ����� ������ ����� ����� ������� � <literal>if</literal> ������
���� ����� � &false;. ����, ����� ��� ����� �� ������
<literal>else</literal> �����, ������ ������� ����� �� ��� ��
���� � <literal>elseif</literal> ���� ����� � &true;. ������,
������� ��� ����� <computeroutput>a is bigger than
b</computeroutput>, <computeroutput>a equal to b</computeroutput>
�� <computeroutput>a is smaller than b</computeroutput>:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($a > $b) {
print "a is bigger than b";
} elseif ($a == $b) {
print "a is equal to b";
} else {
print "a is smaller than b";
}
]]>
</programlisting>
</informalexample>
</para>
<simpara>
����� �-<literal>elseif</literal> ����� ������ ���� ����� �����
����� ���� <literal>if</literal>. �-<literal>elseif</literal> ������
����� ����� �-&true; (�� ���� ���), ����.
������ �� PHP ��� ���� ����� �� 'else if' (���� �����) �� 'elseif' (����� ���)
�������� ���� ���. ���� ������� ��������� ���� ����� �� ��������
�� ��� ������ ��� �����.
</simpara>
<simpara>
����� �-<literal>elseif</literal> ����� �� �� ���� ��������
������ �-<literal>if</literal> ��-<literal>elseif</literal> ����� ��
���� ����� �-&false; ����� �� ����� �-<literal>elseif</literal> ������
���� �-&true;.
</simpara>
</sect1>
<sect1 id="control-structures.alternative-syntax">
<title>����� ��������� �����-����</title>
<para>
PHP ����� ����� ����� ����� ����-���� ���� <literal>if</literal>,
<literal>while</literal>, <literal>for</literal>,
<literal>foreach</literal>, �-<literal>switch</literal>.
������ ������ ����� ������ ����� ������ ���������� (:) �����
������� �������� ������� ������ �� ����� ����:<literal>endif;</literal>,
<literal>endwhile;</literal>,<literal>endfor;</literal>,
<literal>endforeach;</literal>, ��
<literal>endswitch;</literal>.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
]]>
</programlisting>
</informalexample>
</para>
<simpara>
������ ���� �-HTML ������ ����� <literal>if</literal> ����� ������
����������. ����� ���� �� �� ���� �� $a ���� 5.
</simpara>
<para>
������ ���������� ����� �-<literal>else</literal> ��-<literal>elseif</literal>
�� ��. ������ ���� ����� ���� <literal>if</literal> �� <literal>elseif</literal>
��� <literal>else</literal> ������ ���������:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($a == 5):
print "a equals 5";
print "...";
elseif ($a == 6):
print "a equals 6";
print "!!!";
else:
print "a is neither 5 nor 6";
endif;
]]>
</programlisting>
</informalexample>
</para>
<para>
�������� ������, ��� �� ������ �� <link
linkend="control-structures.while">while</link>,
<link linkend="control-structures.for">for</link>, �-<link
linkend="control-structures.if">if</link>.
</para>
</sect1>
<sect1 id="control-structures.while">
<title><literal>while</literal></title>
<para>
������ <literal>while</literal> �� ������� ������� ����� �-PHP.
�� ������� ����� ��� ����������� ���� C. ����� ������� ��
����� <literal>while</literal> ���:
<informalexample>
<programlisting>
<![CDATA[
while (expr) statement
]]>
</programlisting>
</informalexample>
</para>
<simpara>
������� �� ����� <literal>while</literal> ��� �����. ��� ����� ��
PHP ���� �� ������� ���� ����� �� ��� ����� �-<literal>while</literal>
���� ����� �-&true;. ���� �� ������ ���� ���� ��� ��� ������ ������,
�� ��� ����� ���� �� ������ ����� ������, ��� �� ����� �� ������
�� �������� ������� (�� ��� �-PHP ����� �� �� ������� ������� ����� �������).
���� ��� ������ �� ����� �-<literal>while</literal> ���� ����� �-&false; ��������,
������� ����� ������ �� ����� ����� ��� ���.
</simpara>
<para>
����� ������ �-<literal>if</literal>, ���� ���� ����
������ ����� ��� ������ <literal>while</literal> ��� �����
������� �������� �� ��� ����� ������ ����������:
<informalexample>
<programlisting>
<![CDATA[
while (expr): statement ... endwhile;
]]>
</programlisting>
</informalexample>
</para>
<para>
�������� ����� ���� ������ ����� ������ ��� 1 �-10:
<informalexample>
<programlisting role="php">
<![CDATA[
/* example 1 */
$i = 1;
while ($i <= 10) {
print $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
]]>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.do.while">
<title><literal>do..while</literal></title>
<simpara>
������ <literal>do..while</literal> ���� ����� ���
������� <literal>while</literal>, ���� ����� ������ ���� ��
������� ����� ����� ������ ������. ����� ������ ��������
�� ������ ��� ��� ������� <literal>do..while</literal>, ���
������ ���� ����� ��� ��� (�� ����� ���� ���� �����) ���� �������
<literal>while</literal> ����� (��� ����� ���� ������ ������), ����
��� �� ���� �� ���� ����.
(�� ���� ������� �� ������ ���� �-&false;, ������ ����� ���.)
</simpara>
<para>
������� <literal>do..while</literal> �� ���� ����� ��� ����:
<informalexample>
<programlisting role="php">
<![CDATA[
$i = 0;
do {
print $i;
} while ($i>0);
]]>
</programlisting>
</informalexample>
</para>
<simpara>
����� �� ���� ��� ��� �����, ���� ����� ���� �������� �������,
���� �� ������ ���� �-&false; (���� �� $i ���� ���� �-0) ����� ������
����.
</simpara>
<para>
����� C ������� ������ �� �������� ������ ������ <literal>do..while</literal>
����� ����� ���� ����� ������ �� ��� ��-��� ����� ������
<literal>do..while</literal>
������ � �����<link
linkend="control-structures.break"><literal>break</literal></link>.
���� ��� ����� ���:
<informalexample>
<programlisting role="php">
<![CDATA[
do {
if ($i < 5) {
print "i is not big enough";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
print "i is ok";
...process i...
} while(0);
]]>
</programlisting>
</informalexample>
</para>
<simpara>
�� ���� �� ���� �� ���� ����� ��� ����.
���� ����� �������� ����� �� ��� ����� ������ ��.
</simpara>
</sect1>
<sect1 id="control-structures.for">
<title><literal>for</literal></title>
<para>
������ <literal>for</literal> �� ������� ��� ������� �-PHP.
�� ����� ����������� ���� C. ������ �� ����� <literal>for</literal>
���:
<informalexample>
<programlisting>
<![CDATA[
for (expr1; expr2; expr3) statement
]]>
</programlisting>
</informalexample>
</para>
<simpara>
������ ������ (<replaceable>expr1</replaceable>) ����� (����) ���
��� ���� ���� ����� ������ ������.
</simpara>
<simpara>
������ �� ������� <replaceable>expr2</replaceable> �����. �� ����
���� �-&true;, ������ ����� �������� ������� ������.
�� ������ ����� �-&false;, ������ �������.
</simpara>
<simpara>
������ �� ������� ���� ������ <replaceable>expr3</replaceable>.
</simpara>
<simpara>
�� ��� ��������� ���� ����� �� ����� ��� (���).
���� <replaceable>expr2</replaceable> ���, ������ ���� ���
( PHP ������ ���� ������ ��� ��� ���� C ). ����� �� ���� ���� �����
������� ���� ����� ����� ����� �������� ��� ����� ����� <link
linkend="control-structures.break"><literal>break</literal></link> ������
����� ������ ������ ����� &false;.
</simpara>
<para>
�������� ����� ������ �� ������� ��� 1 �-10:
<informalexample>
<programlisting role="php">
<![CDATA[
/* example 1 */
for ($i = 1; $i <= 10; $i++) {
print $i;
}
/* example 2 */
for ($i = 1;;$i++) {
if ($i > 10) {
break;
}
print $i;
}
/* example 3 */
$i = 1;
for (;;) {
if ($i > 10) {
break;
}
print $i;
$i++;
}
/* example 4 */
for ($i = 1; $i <= 10; print $i, $i++);
]]>
</programlisting>
</informalexample>
</para>
<simpara>
����� ������� ������� ��� ����� �� ���� (�� ���� ���� ������ �������), ���
���� ����� �������� ��� ������ ��� ������ <literal>for</literal> ����
����� ������ ������ ����.
</simpara>
<para>
PHP ����� �� ������ ���������� ���������� ������� <literal>for</literal>:
<informalexample>
<programlisting>
<![CDATA[
for (expr1; expr2; expr3): statement; ...; endfor;
]]>
</programlisting>
</informalexample>
</para>
<para>
����� ����� ����� ����� <literal>foreach</literal> ����� ����� ����.
�-PHP 3 �� ����� ����� ���. �-PHP 4 ����� ����� ��
(��� <link linkend="control-structures.foreach">foreach</link> ����� ����).
�-PHP 3 ���� ���� ��� ���� ��-��� ����� ������ <link
linkend="control-structures.while">while
</link> ���������� <function>list</function> �-<function>each</function>.
���� ����� ������� ������ �� �������� ���.
</para>
</sect1>
<sect1 id="control-structures.foreach">
<title><literal>foreach</literal></title>
<para>
PHP ����� �� ����� <literal>foreach</literal> ����� 4 ����.
����� ���� ����� �����, ���� ����� ����� �� ���� ������ �������� �� ����.
������ ������ ��� ���� �����. ���� ����� ����� ����� ������:
<informalexample>
<programlisting>
<![CDATA[
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
]]>
</programlisting>
</informalexample>
</para>
<simpara>
����� ������� ������ ��� ������ �� �����
<literal>array_expression</literal>. ��� ������� ���� �� �� ������
���� ������ <literal>$value</literal> ����� �� ����� ����� �����
����� ���� ��� (�� ������� ���� ���� �� ���� �� ���� ���).
</simpara>
<simpara>
����� ������ ����� �� ���� ������, �� ��� ����� �� �����
������ ���� ������ <literal>$key</literal> ��� �������
(��� ����� ��� ���� �� ������ �������� �� ��� �� ������
�� ���� ������ �����).
</simpara>
<para>
<note>
<para>
���� ����� ����� ����� <literal>foreach</literal>, ���� ��
������ ������ ������ ���� ������ �����. �����, ��� ����
���� ����� �������� <function>reset</function> ���� �����
<literal>foreach</literal>.
</para>
</note>
</para>
<para>
<note>
<para>
��� �� �� ��� ������ <literal>foreach</literal> ����� �� ������
�� ����� ������� ��� �� ����� ���� ���� ���� �� ����� �����
���� ����� ��� ������ <function>each</function>.
</para>
</note>
</para>
<note>
<para>
����� <literal>foreach</literal> �� ����� ������ ������ �����
����� '@'.
</para>
</note>
<para>
������� ����� ���� ������ ������������:
<informalexample>
<programlisting role="php">
<![CDATA[
reset ($arr);
while (list(, $value) = each ($arr)) {
echo "Value: $value<br>\n";
}
foreach ($arr as $value) {
echo "Value: $value<br>\n";
}
]]>
</programlisting>
</informalexample>
�� �������� ����� ����:
<informalexample>
<programlisting role="php">
<![CDATA[
reset ($arr);
while (list($key, $value) = each ($arr)) {
echo "Key: $key; Value: $value<br>\n";
}
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value<br>\n";
}
]]>
</programlisting>
</informalexample>
</para>
<para>
��� ������� �����:
<informalexample>
<programlisting role="php">
<![CDATA[
/* foreach example 1: value only */
$a = array (1, 2, 3, 17);
foreach ($a as $v) {
print "Current value of \$a: $v.\n";
}
/* foreach example 2: value (with key printed for illustration) */
$a = array (1, 2, 3, 17);
$i = 0; /* for illustrative purposes only */
foreach($a as $v) {
print "\$a[$i] => $v.\n";
}
/* foreach example 3: key and value */
$a = array (
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17
);
foreach($a as $k => $v) {
print "\$a[$k] => $v.\n";
}
/* foreach example 4: multi-dimensional arrays */
$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";
foreach($a as $v1) {
foreach ($v1 as $v2) {
print "$v2\n";
}
}
/* foreach example 5: dynamic arrays */
foreach(array(1, 2, 3, 4, 5) as $v) {
print "$v\n";
}
]]>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.break">
<title><literal>break</literal></title>
<simpara>
����� <literal>break</literal> ����� ������ ����� �� ����
����� ������ ���� <literal>for</literal>, <literal>foreach</literal>
<literal>while</literal>, <literal>do..while</literal> ��
<literal>switch</literal>.
</simpara>
<simpara>
����� <literal>break</literal> ����� ���� �� ���� �����
������ �� ���� ���� ����� �������� �������� "�����".
</simpara>
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
$arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
while (list (, $val) = each ($arr)) {
if ($val == 'stop') {
break; /* You could also write 'break 1;' here. */
}
echo "$val<br>\n";
}
/* Using the optional argument. */
$i = 0;
while (++$i) {
switch ($i) {
case 5:
echo "At 5<br>\n";
break 1; /* Exit only the switch. */
case 10:
echo "At 10; quitting<br>\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}
]]>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.continue">
<title><literal>continue</literal></title>
<simpara>
����� <literal>continue</literal> ����� ������ �� ������ ���
���� �� ��� �������� ������� ������ ������� ����� �������� ����.
</simpara>
<simpara>
����� <literal>continue</literal> ����� ���� ����� ���������
������ �� ���� ����� �� ������ ������� ����� ���� �����.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
while (list ($key, $value) = each ($arr)) {
if (!($key % 2)) { // skip odd members
continue;
}
do_something_odd ($value);
}
$i = 0;
while ($i++ < 5) {
echo "Outer<br>\n";
while (1) {
echo " Middle<br>\n";
while (1) {
echo " Inner<br>\n";
continue 3;
}
echo "This never gets output.<br>\n";
}
echo "Neither does this.<br>\n";
}
]]>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.switch">
<title><literal>switch</literal></title>
<simpara>
����� <literal>switch</literal> ������ ������ �� ������ IF ����� �����.
������ ��� ���� ������ �� ���� �� ����� ������ (�� �����) �����
�� ����� ���� ����� ������ �������� �������� ���� ������ �� ������.
��� ����� ���� �� ���� ����� ������ <literal>switch</literal>.
</simpara>
<para>
���� �������� ����� ������ ��� ����� ������ ����� ���.
������� ��� ����� ����� ����� <literal>if</literal> �������
��� ����� ������ <literal>switch</literal>:
<informalexample>
<programlisting role="php">
<![CDATA[
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($i == 2) {
print "i equals 2";
}
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
}
]]>
</programlisting>
</informalexample>
</para>
<para>
���� ����� ��� ����� <literal>switch</literal> ����� ��� ����� ������.
����� �-<literal>switch</literal> ���� �� ����� ����� ����� �����
������ �� �� ���� ����� <literal>case</literal> �� ��� ����� �����
���� �-<literal>switch</literal>, ��� PHP ����� ����. �� ���
���� �-<literal>switch</literal> �� ����� �-<literal>break</literal> �������.
�� �� ����� ����� <literal>break</literal> ����� �� ���� <literal>case</literal>
�� PHP
����� ����� ����� �-<literal>case</literal> �����. ������:
<informalexample>
<programlisting role="php">
<![CDATA[
switch ($i) {
case 0:
print "i equals 0";
case 1:
print "i equals 1";
case 2:
print "i equals 2";
}
]]>
</programlisting>
</informalexample>
</para>
<simpara>
������ ��, �� ���� �� $i ���� �-0 ,����� ���� �� �� ������ �-print !
�� ���� ���� �-1 ����� ���� �� ��� ������� �������� ��� ����
���� ���� �-2 ���� �� ����� �-print ������� ����� �� ������ �������.
�����, ���� ����� �� ������ �-<literal>break</literal> (����� ����� ���
�� ���� ������ ������ �� ������).
</simpara>
<simpara>
������ <literal>switch</literal> ������ ����� ��� ��� ���� �������
����� ��� ���� ������<literal>case</literal>. ������ <literal>elseif</literal>
������ ����� ��� �����. �� �� ���� ���� ����� ���� ������
����� �� and �� or ������, ����� ������ �-<literal>switch</literal>
����� �� ������ ������� ����� ���� ���� ������� �� ��� ������ if �-elseif.
</simpara>
<para>
����� ������� �� ���� case ����� ����� ���� ����� ����� ������ �����
���� �-case ���.
<informalexample>
<programlisting role="php">
<![CDATA[
switch ($i) {
case 0:
case 1:
case 2:
print "i is less than 3 but not negative";
break;
case 3:
print "i is 3";
}
]]>
</programlisting>
</informalexample>
</para>
<para>
���� ��� �� ���� case ����� ����, ��� ���� �-default.
����� �������� ����� case ���� default , ��� ����� ���� �� ���
����� �� ����� �-<literal>switch</literal> ��� ��� ������ �-case
���� �� ����� ���� ���� ����� �� ���� �-case. ������:
<informalexample>
<programlisting role="php">
<![CDATA[
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
}
]]>
</programlisting>
</informalexample>
</para>
<para>
������ ����� �-<literal>case</literal> ���� ����� �� ����� ���� ����
��� ���� �������� (integer) �� ���� ����� (float) �� ������.
�� ���� ������ ����� ��� �� ��� ����� ���� ����� ����.
</para>
<para>
�� ������ ���������� ����, ��� ���� <link
linkend="control-structures.alternative-syntax">����� ��������� �����-����</link>.
<informalexample>
<programlisting role="php">
<![CDATA[
switch ($i):
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
endswitch;
]]>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.declare">
<title><literal>declare</literal></title>
<para>
���� �-<literal>declare</literal> ���� ������ �����
����� ���� ���� ������. ������ ���� ������ �� ����-����
�����:
<informalexample>
<programlisting>
<![CDATA[
declare (directive) statement
]]>
</programlisting>
</informalexample>
</para>
<para>
��� �-<literal>directive</literal> (�����) ����� �� ����� ������� ����
�-<literal>declare</literal>. ��� ���, ������ ������ ������
��� ����� �-<literal>ticks</literal>. (���� ����� ����� ���� ��
����� <link linkend="control-structures.declare.ticks">ticks</link> �������)
</para>
<para>
��� �-<literal>statement</literal> ������ <literal>declare</literal>
��� ����� �� ���� �� ������ ������. ����� �-<literal>directive</literal>
���� �� ���� ����� �� ������� ������� ������ ������� ������.
</para>
<sect2 id="control-structures.declare.ticks">
<title>Ticks</title>
<para>
���� �-ticks ����� �� <replaceable>N</replaceable> ����� ����
����� ���� ������ (low-level) ��-��� ����� ����� ������ ���
������ <literal>declare</literal>.
���� �� <replaceable>N</replaceable> ��� ����� ������ ������
�-<literal>declare</literal> ��-��� ����� �����
<literal>ticks=<replaceable>N</replaceable></literal>.
</para>
<para>
������� ������� ������ �� ���� tick ����� ��-��� ��������
<function>register_tick_function</function>. ���� ������ ���� ����� ����.
���� �� ��� ����� ���� ���� ������ ��� ��� tick.
</para>
<para>
<example>
<title>����� �� ��� PHP</title>
<programlisting role="php">
<![CDATA[
<pre>
<?php
// A function that records the time when it is called
function profile ($dump = FALSE)
{
static $profile;
// Return the times stored in profile, then erase it
if ($dump) {
$temp = $profile;
unset ($profile);
return ($temp);
}
$profile[] = microtime ();
}
// Set up a tick handler
register_tick_function("profile");
// Initialize the function before the declare block
profile ();
// Run a block of code, throw a tick every 2nd statement
declare (ticks=2) {
for ($x = 1; $x < 50; ++$x) {
echo similar_text (md5($x), md5($x*$x)), "<br>";
}
}
// Display the data stored in the profiler
print_r (profile (TRUE));
?>
</pre>
]]>
</programlisting>
</example>
������ ���� ����� �� ���� ������ ����� �-'declare'
��-��� ����� ���� ���� �� ���� �� ����� ����� ���� ������.
���� �� ���� ���� ����� ����� ������ ������ �������� �����
���� ������. ���� ���� ����� ��� �� ������ ����� ��
������ �-ticks ��� ���� ����� �����.
</para>
<simpara>
����� ticks ������ ������ ������, ���� ����� ������ ����,
����� ����� ���\��� ���� ���� ���� ������ �����.
</simpara>
<simpara>
���� �� �� ��������<function>register_tick_function</function> �-
<function>unregister_tick_function</function>.
</simpara>
</sect2>
</sect1>
<sect1 id="function.return">
<title>return</title>
<simpara>
�� ������ ����� ������ �� ���� �������, ����� �-<function>return</function>
����� ���� �� ���� �������� ������� ������ �� ���� ������ �� ����
������ �� ��������. ����� <function>return</function> ����� ��
����� �� ����� <function>eval</function> �������.
</simpara>
<simpara>
�� ������ ����� �������� �� ���� ����� ����� �� �������, ���� �������
������. �� ������ ������ ����� ��-��� ����� <function>include</function> ��
<function>require</function>, ���� ������� ������ ������ �������� ������
����� ������� �� �����. �����, ��� �-<function>return</function> �����
����� �� �������� �-<function>include</function>. �� ������
�-<function>return</function>
������ �������� �����, ������ ����.
�� ������� ������ ����� �������� <link
linkend="ini.auto-prepend-file">auto_prepend_file</link> �� <link
linkend="ini.auto-append-file">auto_append_file</link>
�<link linkend="configuration.file">���� �������</link>, ���� ������� �����.
</simpara>
<simpara>����� ���� �� ����� �<link
linkend="functions.returning-values">����� �����</link>.
</simpara>
<note>
<simpara>
��� �� �-<function>return</function> ��� ���� �� ����
��� ������� ���� �������� ������� �� ������ ������
<emphasis>��</emphasis> ������� ����� ����� ����� �������
�� �� ��� �� ���� ���.
</simpara>
</note>
</sect1>
<sect1 id="function.require">
<title><function>require</function></title>
<simpara>
����� <function>require</function> ����� ������ �� ������
���� ������.
</simpara>
<simpara>
����� <function>require</function> ����� ������ �� ������
���� ������. ���� ����� ���� ���� ����� ������ ���� �����
������ �������� <function>include</function>.
</simpara>
<simpara>
������� <function>require</function> �-<function>include</function>
���� ��� ���� ��� ���� ����� �� �� ������ ������� �� ����� ����� ������ �����.
����� <function>include</function> ������
<link linkend="internal.e-warning">�����</link> ���� ������
<function>require</function> ������ <link linkend="internal.e-error">
Fatal Error</link> - ����� ������ ������ ����� �� �������.
�� ������ ����� �� ���� ������� ����� ����� �� ����, �� ������
�-<function>require</function>. ����� <function>include</function>
���� ������ ����� ���.��� ��, ����� ����� �� ���� ��
<link linkend="ini.include-path">include_path</link>.
</simpara>
<para>
<example>
<title>����� ������ �� <function>require</function></title>
<programlisting role="php">
<![CDATA[
<?php
require 'prepend.php';
require $somefile;
require ('somefile.txt');
?>
]]>
</programlisting>
</example>
</para>
<simpara>
�� ����� ������ ������ <function>include</function> �������� ������.
</simpara>
<note>
<simpara>
����� PHP 4.0.2 ����, ����� <function>require</function> ���� ����� �� ����
����� ��� �� �� ��� �� ����� ����� ���� ���� �������. ���� ������ �� �����
�� <function>require</function> �� �� ����� �� ������ �����
<function>require</function> �� ����, �� ���� ����� �-<function>require</function>
�� ����. �� <function>require</function> ����� ���� ����� ���� �����
����� ����� ���. ���� ���� ���� ���� ���� ����� ������ �� ����� ������
����� ��� ��� ����.
</simpara>
</note>
<simpara>
����� ����,�� ����� �� ������ �� <function>include</function>,
<function>require_once</function>,
<function>include_once</function>, <function>eval</function>,
<function>file</function>, <function>readfile</function>,
<function>virtual</function> u- <link
linkend="ini.include-path">include_path</link>.
</simpara>
</sect1>
<sect1 id="function.include">
<title><function>include</function></title>
<simpara>
����� <function>include</function> ����� ������ �� ������
���� ������.
</simpara>
<simpara>
������� <function>require</function> �-<function>include</function>
���� ��� ���� ��� ���� ����� �� �� ������ ������� �� ����� ����� ������ �����.
����� <function>include</function> ������
<link linkend="internal.e-warning">�����</link> ���� ������
<function>require</function> ������ <link linkend="internal.e-error">
Fatal Error</link> - ����� ������ ������ ����� �� �������.
�� ������ ����� �� ���� ������� ����� ����� �� ����, �� ������
�-<function>require</function>. ����� <function>include</function>
���� ������ ����� ���.��� ��, ����� ����� �� ���� ��
<link linkend="ini.include-path">include_path</link>.
</simpara>
<simpara>
���� ���� ����� ����� include ��� ���� �� <link
linkend="language.variables.scope">���� �������</link> ����
������. �����, �� ����� ���� ���� ������� ����� ������
������, ��� ���� ������ ��� �-include �� ��.
</simpara>
<para>
<example>
<title>����� ������ �-<function>include</function></title>
<programlisting role="php">
<![CDATA[
vars.php
<?php
$color = 'green';
$fruit = 'apple';
?>
test.php
<?php
echo "A $color $fruit"; // A
include 'vars.php';
echo "A $color $fruit"; // A green apple
?>
]]>
</programlisting>
</example>
</para>
<simpara>
�� ������ ����� ���� ������� ������� �����, �� ���� �����
����� ����� ��� ��� ��������� ���� �� ���� ���� ��
���� ������� �� �������� ����.
</simpara>
<para>
<example>
<title>����� ���� �������</title>
<programlisting role="php">
<![CDATA[
<?php
function foo()
{
global $color;
include 'vars.php';
echo "A $color $fruit";
}
/* vars.inc is in the scope of foo() so *
* $fruit is NOT available outside of this *
* scope. $color is because we declared it *
* as global. */
foo(); // A green apple
echo "A $color $fruit"; // A green
?>
]]>
</programlisting>
</example>
</para>
<simpara>
���� ���� �����, ����� ���� �"��� "PHP �����
�"��� "HTML ������ �����. ����� ����, �� ��� �����
���� ����� �<link linkend="language.basic-syntax.phpmode">�����
����� ������ ������</link>.
</simpara>
<simpara>
�� ������� ������� "<link linkend="ini.allow-url-fopen">
URL fopen wrappers</link>" (���� ����� ���� �������),
�� ���������� ����� ����� HTTP ����� �� ���� �����.
�� ��� ����� ���� ���� PHP, ����� ����� ������ ������ ����� HTTP GET.
�� ���� ����� ������ �� ���� ����� ����� �� ������� �������� �����.
������� ������ ���� ���� ������� ������ ������� ������.
</simpara>
<para>
<example>
<title>����� �-<function>include</function> ��� HTTP</title>
<programlisting role="php">
<![CDATA[
<?php
/* This example assumes that www.example.com is configured to parse .php *
* files and not .txt files. Also, 'Works' here means that the variables *
* $foo and $bar are available within the included file. */
// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';
// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';
// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';
$foo = 1;
$bar = 2;
include 'file.txt'; // Works.
include 'file.php'; // Works.
?>
]]>
</programlisting>
</example>
�� ����� �� ������ �� <link linkend="features.remote-files">����� �������</link>,
<function>fopen</function> �- <function>file</function> ����� ���� �����.
</para>
<para>
���� �������� <function>include</function> �-<function>require</function>
�� ���� ����� ����, ���� ����� ���� �������� �������� ����
����� ������ �� ������.
</para>
<para>
<example>
<title>������ �� ����� include()</title>
<programlisting role="php">
<![CDATA[
<?php
// This is WRONG and will not work as desired.
if ($condition)
include $file;
else
include $other;
// This is CORRECT.
if ($condition) {
include $file;
} else {
include $other;
}
?>
]]>
</programlisting>
</example>
</para>
<simpara>
���� ������ ����� return ���� ���� ����� ����� ����� �� ������ �������
�� ������ ������� �����. ��� ��, ���� ������ ���� ����� ����� �������
����� ����� ������ �������� �����.
</simpara>
<note>
<simpara>
����� 3 �� PHP �� ����� ����� �-<function>return</function>
��� ���� ������� ���� ��� ����� ���� ���� �� ���� �����.
</simpara>
</note>
<para>
<example>
<title>������ <function>include</function> �-<function>return</function></title>
<programlisting role="php">
<![CDATA[
return.php
<?php
$var = 'PHP';
return $var;
?>
noreturn.php
<?php
$var = 'PHP';
?>
testreturns.php
<?php
$foo = include 'return.php';
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
?>
]]>
</programlisting>
</example>
</para>
<simpara>
������ <literal>$bar</literal> ���� �� ���� <literal>1</literal> �� ������
����� ������. ���� �� ����� ��� �������� �������. ������� ������ ������
<function>return</function> ����� ����� ������� - ��.
����� ������ ������ ���� ���� ������ ���� ���� ��� ����� �-
<function>fopen</function>, <function>file</function> �� ��� �����
�-<function>include</function> ������ ��
<link linkend="ref.outcontrol">�������� ������ ����</link>.
</simpara>
<simpara>
���� �� ������ �� <function>require</function>, <function>require_once</function>,
<function>include_once</function>, <function>readfile</function>,
<function>virtual</function> �-
<link linkend="ini.include-path">include_path</link>.
</simpara>
</sect1>
<sect1 id="function.require-once">
<title><function>require_once</function></title>
<para>
����� <function>require_once</function> ����� ������ �� ������
���� ������. ��������� ��� ������ <function>require</function>
�� ���� ���� ������ ��� ��� ��� ����� ������ ��� ���� �����
����� �� �������, ��� �� ����� ��� �����. �� ����� ������ �� �����
<function>require</function> ����� ���� �� ���� ������ �� ����� ��.
</para>
<para>
�� ������ �-<function>require_once</function> ������ ���
���� ������ �� ���� ������ ���� ����� ����� ����� ��� ����
����� ����� ���� ��� ����� ����� ������ �� �������� ������� �����.
</para>
<para>
����� ������ �-<function>require_once</function> �-
<function>include_once</function> ���� ����� ���� ��
<ulink url="&url.php.pear;">PEAR</ulink> ������ �����
PHP �������.
</para>
<note>
<para>
�������� <function>require_once</function> ����� �� ����� PHP 4.0.1pl2
</para>
</note>
<para>
���� ���� ���� ����� ������: <function>require</function>,
<function>include</function>, <function>include_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
�- <function>virtual</function>.
</para>
</sect1>
<sect1 id="function.include-once">
<title><function>include_once</function></title>
<para>
����� <function>include_once</function> ����� ������ �� ������
���� ������. ��������� ��� ������ <function>include</function>
�� ���� ���� ������ ��� ��� ��� ����� ������ ��� ���� �����
����� �� �������, ��� �� ����� ��� �����. �� ����� ������ �� �����
<function>include</function> ����� ���� �� ���� ������ �� ����� ��.
</para>
<para>
�� ������ �-<function>include_once</function> ������ ���
���� ������ �� ���� ������ ���� ����� ����� ����� ��� ����
����� ����� ���� ��� ����� ����� ������ �� �������� ������� �����.
</para>
<para>
����� ������ �-<function>require_once</function> �-
<function>include_once</function> ���� ����� ���� ��
<ulink url="&url.php.pear;">PEAR</ulink> ������ �����
PHP �������.
</para>
<note>
<para>
�������� <function>include_once</function> ����� �� ����� PHP 4.0.1pl2
</para>
</note>
<para>
���� ���� ���� ����� ������: <function>include</function>,
<function>require</function>, <function>require_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
�-<function>virtual</function>.
</para>
</sect1>
</chapter>
<!-- 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:"../../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
-->