glace Sun Apr 8 03:13:57 2001 EDT
Added files:
/phpdoc/hk/language basic-syntax.xml constants.xml
control-structures.xml expressions.xml
functions.xml oop.xml operators.xml
references.xml types.xml variables.xml
Log:
use xml
Index: phpdoc/hk/language/basic-syntax.xml
+++ phpdoc/hk/language/basic-syntax.xml
<chapter id="language.basic-syntax">
<title>�y�k</title>
<sect1 id="language.basic-syntax.phpmode">
<title>�i�J PHP �y���Ҧ�</title>
<para>
�b HTML ����J PHP �����O�@���|�ؤ�k: </para>
<para>
<example>
<title>Ways of escaping from HTML</title>
<programlisting>
1. <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
2. <?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?>
3. <script language="php">
echo ("some editors (like FrontPage) don't
like processing instructions");
</script>
4. <% echo ("You may optionally use ASP-style tags"); %>
<%= $variable; # This is a shortcut for "<%echo .." %>
</programlisting>
</example>
</para>
<para>
�W���C�X����k���Ĥ@�إu�� PHP �Q�]�w������ "�u����" �ɤ~�|���ġC �]�w��k�i�H
<!-- via the <function>short_tags</function> function,-->�b�ճ]��� PHP.INI ����
<link linkend="ini.short-open-tag">short_open_tag</link>
�]���u�ȡA �Ϊ̦b�sĶ PHP �ɰ��� <command>configure</command>
�ɥ[�J --enable-short-tags �o�ӿﶵ�C
</para>
<para>
The second way is the generally preferred method, as it allows for the
next generation of XHTML to be easily implemented with PHP.
</para>
<para>
�ĥ|�ؤ�k�]�u���� ASP �κA������ �Q���\�ɤ~���ġC �o�ݭn�ճ]
<link linkend="ini.asp-tags">asp_tags</link>
�o�ӰѼơC
<note>
<para>�� ASP-style ���Ҫ��䴩�q PHP �� 3.0.4 ���}�l.</para>
</note></para>
<para>
�{���q�������аO�N�|�]�A���H�b��᪺����Ÿ��C (���p������Ÿ����ܡC)
</para></sect1>
<sect1 id="language.basic-syntax.instruction-separation">
<title>���j���O</title>
<simpara>
PHP �U���O�椧�������j��k�M C�B PERL �O�@�˪��C - �C����O���Τ��� ";" ���}�C
</simpara>
<para>
�ѩ�{���q�������ҦP�˥N�����O�����A �]���H�U����q�{���O�ĪG�O�@�˪��C
<informalexample>
<programlisting>
<?php
echo "This is a test";
?>
<?php echo "This is a test" ?>
</programlisting>
</informalexample></para></sect1>
<sect1 id="language.basic-syntax.comments">
<title>�[�`������k</title>
<para>
PHP �W�i�H�� C�B C++�B �M Unix shell ���`����k�C �b�`�����������e�N�Q PHP
�����������C ��p�� :
<informalexample><programlisting>
<?php
echo "This is a test"; // This is a one-line c++ style comment
/* This is a multi line comment
yet another line of comment */
echo "This is yet another test";
echo "One Final Test"; # This is shell-style style comment
?>
</programlisting>
</informalexample></para>
<simpara>
�ܩإu�`�Ѥ@�檺�`���Ÿ����@�νd��u�|�b���椺���ġC ( �p���椤�P�ɥX�{ PHP
�{�F�q�����Ÿ� "?>" �h�b�Ÿ��᪺��r�N���|�Q�����C)</simpara>
<informalexample><programlisting>
<h1>This is an <?php # echo "simple";?> example.</h1>
<p>The header above will say 'This is an example'.
</programlisting></informalexample>
<simpara>
�p�G�O C ���榡�Ӱ��`���A �`�N���n���U�ү�b�`�����A�[�`���A �_�h�|�y�����~�C
</simpara>
<informalexample><programlisting>
<?php
/*
echo "This is a test"; /* This comment will cause a problem */
*/
?>
</programlisting></informalexample></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
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/constants.xml
+++ phpdoc/hk/language/constants.xml
<chapter id="language.constants">
<title>�`��</title>
<simpara>
PHP �ۤv���ѤF�@�DZ`�ơA �]���\�{������ɥt�~�A�w�q�U�ر`�ơC�`�ƩM�ܼƫܬۦ��A
���̤����u����Ӥ��O�G �����`������
<function>define</function> ��ƨөw�q�A �t�~�N�O�@���w�q��`�ƪ��Ȥ��i���ܡC
</simpara>
<para>
�t�Τ��w���w�q���`�ƥ]�A:
<variablelist>
<varlistentry>
<term>__FILE__</term>
<listitem>
<simpara>
�x�s�F�ثe���Q���檺��W�r�C �p�G�Φb�Q include() �� require() ������A
�h�x�s�F����W�r�ӫD�Q include() �� reuqire() ��W�r�C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>__LINE__</term>
<listitem>
<simpara>
�{�b���b�Q���R/�ѪR�����O��C �p�G���O�O�b�Q include() �� require() ����A
�h�x�s���O�b�Ӥl����渹�C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_VERSION</term>
<listitem>
<simpara>
�H��y�����A�x�s�F�{�� PHP �������C �Ҧp '3.0.8-dev'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_OS</term>
<listitem>
<simpara>
�B�� PHP ���@�~�t�ΡA �p 'Linux'. </simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>TRUE</term>
<listitem>
<simpara>
�N����ȯu/�O�C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>FALSE</term>
<listitem>
<simpara>
�N����Ȱ�/�D�C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_ERROR</term>
<listitem>
<simpara>
�N���X�{�F�ëD�ѪR�W�����~�äޭP�{���L�k�~�����U�h�C </simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_WARNING</term>
<listitem>
<simpara>
�N���X�{�Fĵ���� PHP �|�~�����{���C �o�˪�ĵ���i�ε{���������C�������Ҥl�p
<function>ereg</function>
�����F���˿��F�C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_PARSE</term>
<listitem>
<simpara>
�ѪR���b���R���O��ɵo�{�F���~�A �b�o���p�U�L�k�^�_�{��������C
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_NOTICE</term>
<listitem>
<simpara>
�N�����ǨƤ���l�A �i��O�o�ͤF���~�]�i�ण�O�C �o�����D���Ҥl��:
�����p�r���ި��ΰ}�C�ɨS�������p�r�Τ��A�_�ӡB �S�����w�ܼƪ������ܼơE�E�E
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_ALL</term>
<listitem>
<simpara>
??
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
�o�ǥ� E_ ���Y���`�Ƴq�`�O�M
<function>error_reporting</function>��ưt�X�Ψӽվ� error reporting level �A
�N�O���ճ]�����ǿ��~�|�Q�B�z�A �����Ƿ|�Q�����C
</para>
<para>
�p�n�w�q�ۤv���`�ơA �Х�
<function>define</function> ��ơC </para>
<para>
�d�߳o���O�`�ƦӤ��O C ���檺�����G �`�ƥu���x�s�X�k���ƾڡC
<example>
<title>�]�w �`��</title>
<programlisting>
<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?>
</programlisting>
</example>
<example>
<title>__FILE__ �M __LINE__ ���Ϊk
</title>
<programlisting>
<?php
function report_error($file, $line, $message) {
echo "An error occured in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?>
</programlisting>
</example></para>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/control-structures.xml
+++ phpdoc/hk/language/control-structures.xml
<chapter id="control-structures">
<title>����{�����y�{</title>
<simpara>
PHP �{�������O�Ѥ@�y�y���y�y�Һc���C �y�y�i�H�����ܼƪ��ȡB �եΨ�ơB ����j��B
��������y�{���Ʀܤ���]����(�ťջy�y)�C �@�y�y�y�q�`�H ';' �����@�����C �Q�Ϊ�A�� '{
}'�i�H��n�h���y�y�զ��@�աA �o�˲զ����y�ե��ۤv�]�O�@�y�y�y�C
���`�|���ЦU���U�˪��y�y�����C
</simpara>
<sect1 id="control-structures.if">
<title><literal>if</literal></title>
<para>
if �O�{�����y�������䭫�n���զ������A �� PHP ���]���ҥ~�C
�����ѤF���ݭn���椣�P�{���q���\��C PHP �ҥΪ� if ���c�M C �ҥΪ��S���P�G
<informalexample>
<programlisting>
if (expr)
statement
</programlisting>
</informalexample>
</para>
<simpara>
if �O�{�����y�������䭫�n���զ������A �� PHP ���]���ҥ~�C
�����ѤF���ݭn���椣�P�{���q���\��C PHP �ҥΪ� if ���c�M C �ҥΪ��S���P�G
</simpara>
<para>
�H�U�d�ҷ|���X a is bigger than b �p�G $a ���Ȥ� $b���j:
<informalexample>
<programlisting role="php">
if ($a > $b)
print "a is bigger than b";
</programlisting>
</informalexample>
</para>
<para>
�q�`�b�M�w�F�����A�i��n����h�L�@�y���O�A ���M�A�����C�ӫ��O�e���Τ@�� if �A
�A�u�ݭn��o�ǭn���檺���O�� '{ }' �զ��y�մN��F�C �n���H�U���{���q�|��ܥX a is
bigger than b �p�G $a �� $b �j�A �P�ɷ|�� $a ���ȧۨ� $b��:
<informalexample>
<programlisting role="php">
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
</programlisting>
</informalexample>
</para>
<simpara>
If �i�H�b�O�� if �����X�{�A ���o�˪����p�٬��_���� if�A PHP ���\�L���h���_�����c�C
�p���A�b�s�{�����ܤj���ۥѫרӱ���{�����y�{�C
</simpara>
</sect1>
<sect1 id="control-structures.else">
<title><literal>else</literal></title>
<para>
���ɭԧA�|����ի��O�A �@�զb���߮ɰ���A �t�@�զb�����߮ɰ���C �o�ɥ� else
�N��K�ܦh�F�C else �ɥR if ���\��G �p�G if �y�y�������F�������߮ɡA if
���|�������O�աA �ӷ|���� else ���᪺���O�աC ���U���{���|���X a is bigger than
b �p�G $a �j�L $b�A �Ϥ��h���X a is NOT bigger than b :
<informalexample>
<programlisting role="php">
if ($a > $b) {
print "a is bigger than b";
} else {
print "a is NOT bigger than b";
}
</programlisting>
</informalexample>
else �������O�եu�� if ���F���t�⪺���G�O�����ɭԤ~�|�Q����C�p�G�٦��O�� elseif
���F�����ܡA �o�Ǫ��F�������G�]�n�O���~��C(�ݤU��)
</para>
</sect1>
<sect1 id="control-structures.elseif">
<title><literal>elseif</literal></title>
<para>
elseif�A �@�ݴN���D�Oif �M else���V�X��C Like else�@�ˡA ���ɥR�F if �y�y���\��G
���b if �������߮ɤ~�|����C���M else���@�˪��O�A elseif ���F�n�D if
�������ߡA ���P�ɭn�D�ۤv�����ߡA�_�h�����|�����۪��{���q�C �U�C�ܽd��
$a�B$b ���j�p���X a is bigger than b�� a equal to b �� a is smaller than b:
<informalexample>
<programlisting role="php">
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>
�i�H���n�X�� elseif�X�{�b�P�@�� if �y�y���C �Ĥ@�Ӧ��ߪ� elseif �|�Q����C �s�g PHP
�{���ɧA�]�i�H�Ψ�Ӧr�� 'else if' �A �o�M��r�� 'elseif' �O�ۦP���C
���M��̦b�y�k�������W�����P�A���Ҧ����\��M���G���O�S�����O���C (�p�A���x C ���ܡA
�o�M C �����p�O�@�ˡC)
</simpara>
<simpara>
�A�����@���A elseif �������O�եu�������e���� if �M��L�� elseif
�������ߨåB���ۤv�����߮ɤ~�|�Q����C
</simpara>
</sect1>
<sect1 id="control-structures.alternative-syntax">
<title>���ĥy�k</title>
<para>
PHP ���H�U������y���ѤF�t�~�@�ؼg�k�A�o�ǻy�y�]�A�Gif�B while�B for�B switch�C
���Ī��g�k�N�O����O�ն}�Y�� '{' �A���ܦ��_�� ':'�G �P�ɵ����� '}' ���O�ܦ� endif;
endwhile; endfor; endswitch;�C
<informalexample>
<programlisting role="php">
<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
</programlisting>
</informalexample>
</para>
<simpara>
�b�W�z�ܽd���A HTML �榡���y�l "A is equal to 5" �Q�]�b�@�� if �y�y�����C
�o���p�U�u���� $a �O 5 �ɸӥy�l�~�Q�L�X�ӡC
</simpara>
<para>
���Ī��y�k�]�i�Φb else�M elseif �W�C�U���N�O if �[�W elseif �M else �����ļg�k�C
<informalexample>
<programlisting role="php">
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>
�t�Ь� <link linkend="control-structures.while">while</link>,
<link linkend="control-structures.for">for</link>, <link
linkend="control-structures.if">if</link> ������L�ܽd�C
</para>
</sect1>
<sect1 id="control-structures.while">
<title><literal>while</literal></title>
<para>
while �j��O PHP �س�²�檺�j��Φ��C �M c �� while �@�ˡA �����y���O�G
<informalexample>
<programlisting>
while (expr) statement
</programlisting>
</informalexample>
</para>
<simpara>
while ���N��ܪ����G �u�n����������F�����ߡA ���|�s PHP �����a���� while ���������O�C
�]���C�� while ���������O��������᳣�|�ˬd�@�� while ����O�_�̵M���ߡA
�ҥH�N�����b���O���ɤw�g���ܡA
�����n���Ҧ����O��������~�|���X�j��C(�C�����槹�j�餤�Ҧ������O���s�������F�@���`��)
���p while ���F���b�@�}�l���ɭԴN�����ߡA�� while ���������O�ڥ����|�Q����
(�s���`��)�C
</simpara>
<para>
�M if �@�ˡA �A�i�H��n�h���O�� '{ }' �]�_�ө�bwhile �j�餧���C �A�]�i�H�� while
�����ĥy�k�Ӽg:
<informalexample>
<programlisting>
while (expr): statement ... endwhile;
</programlisting>
</informalexample>
</para>
<para>
�U����ӥܽd�N���ͬۦP�����G�G �� 1 �� 10 �L�X�� <informalexample>
<programlisting>
/* 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>�j��</literal></title>
<simpara>
do.while �j�� �M while �j��t���h�A������̫�~�ˬd�������O�_���ߡC �o�˫O�ҤF
do.while �������O�_�X�|�Q����@���C �ѩ� while �O�b�@�}�Y�K�ˬd����A �ҥH�� while
���ܥi��@���`���]���椣�F�C
</simpara>
<para>
do.while �j�� �u���@�ӥy�k�A �S���O�����ļg�k :
<informalexample>
<programlisting role="php">
$i = 0;
do {
print $i;
} while ($i>0);
</programlisting>
</informalexample>
</para>
<simpara>
�W�����{���u�|�]�@���A �]�����O���槹�F�~�ˬd����~�o�{��ӱ����ߩ�O���X�j��C
</simpara>
<para>
�� C �s�{������i�����o�t�@�� do.while �j�� ���Ϊk�G �� <link
linkend="control-structures.break"><literal>break</literal></link>
���O�M do.while(0) �j��Өϵ{���b���椤�~�פ�C�U�C�{���q�ܽd�o�@�ӥΪk:
<informalexample>
<programlisting role="php">
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>
�a�ϧA�ݤ��X�W���{������������]�S���Y�C �N�⤣�� do.while
���o�ӯS�ʤ]�@�˥i�H�g�X�\��ܱj���{���C
</simpara>
</sect1>
<sect1 id="control-structures.for">
<title><literal>for �j��</literal></title>
<para>
for �j�� �i���O PHP ���̽������j�����C���̪��Ϊk�M�b C �����Ϊk�èS�����O:
<informalexample>
<programlisting>
for (expr1; expr2; expr3) statement
</programlisting>
</informalexample>
</para>
<simpara>
�����Ĥ@�Ӫ��F�� (expr1) �L�צp�|�t��@�� </simpara>
<simpara>
�M��b�C�Ӵ`���}�l�e expr2 ���|�Q��X�ӡA �p�G�o�X���G���ߪ��ܡA
�j�餤�����O�K�Q����A �p�G expr2 �����ߪ��ܡA �K�|���X�j��C
</simpara>
<simpara>
�C�@�Ӵ`����������q���|�t��@�� expr3�C </simpara>
<simpara>
�T�Ӫ��F��������@�ӳ��i�H�O�Ū��C expr2 �Ū��ܥN���j��|�L��Ҧa����U�h�C (PHP �M
C �@�ˡA �۰ʧ�Ū����F�������O���ߪ�) �oť�W�h�ܵL��A ����ڤW�A�i��Q�b�j�餤��
<link
linkend="control-structures.break"><literal>break</literal></link>
���覡�ӵ����C </simpara>
<para>
�H�U�C�@�ӨҤl���|��� 1 �� 10: <informalexample>
<programlisting role="php">
/* 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>
���M�A �b�W�����ܽd���ݰ_�ӥu���Ĥ@�� (�]�\�]�H�߷R�ĥ|�ӨҤl) �̥��W�A �����L���ɭԦb
for �j�� �ΪŪ����F���i�H�O�s�g�{���ܫܤ�K�C
</simpara>
<para>
for �j�� �]�������t�@�ؼg�k�C <informalexample>
<programlisting>
for (expr1; expr2; expr3): statement; ...; endfor;
</programlisting>
</informalexample>
</para>
<para>
�����{���y�����ӥs foreach ���R�O�Ӧs���}�C�M������ƪ��C PHP3 �S���o�˫��O�� PHP4
���C (��
<link
linkend="control-structures.foreach">foreach</link>)�C�� PHP3 �ɡA�A�n�P�ɥ�
<link linkend="control-structures.while">while</link> �M<function>list</function> �H��
<function>each</function>
��Ƥ~�৹���ۦP���u�@�C �Q���D����ܽЬݦ����o�Ǩ�ƪ����`�C
</para>
</sect1>
<sect1 id="control-structures.foreach">
<title><literal>foreach</literal></title>
<para>
PHP4 (PHP3 �èS��) �[�J�F foreach ���\��C�o�\��b PERL �M��L�y���������C
�Υ��i�H�ܤ�K�a�s���}�C�C �X�k���y������ӡG
�ĤG�ӥu�O��Ĥ@�ӥy�k�@�F�@�I��ʦ��ܦ��ΡC�p�U�G
<informalexample>
<programlisting>
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
</programlisting>
</informalexample>
</para>
<simpara>
�Ĥ@�ӥy���C���`�����|��}�C array_expression �����@�Ӥ������Ȧs���ܼ� $value
������}�C���Ҧ��������Χ��F�C
</simpara>
<simpara>
�ĤG�ӥy���M�Ĥ@�Ӯt���h�A ���O�b�F $value �|�x�s�F�������ȡA $key
�ٷ|�x�s�F�ثe�����������C
</simpara>
<para>
<note>
<para>
�� foreach �}�l�ɤ��m���}�C���з|���V�}�C�����Ӥ�������m�C
�o�N���A�����b�C�� foreach �e�ե�
<function>reset</function> ��ơC
</para>
</note>
</para>
<para>
<note>
<para>
Also note that <literal>foreach</literal> operates on a copy of
the specified array, not the array itself, therefore the array
pointer is not modified like with the each construct.
</para>
</note>
</para>
<para>
�b�U�����d�ҡA �A���i�ݥX���̥\��O�@�˪�: <informalexample>
<programlisting role="php">
reset ($arr);
while (list(, $value) = each ($arr)) {
echo "Value: $value<br>\n";
}
foreach ($arr as $value) {
echo "Value: $value<br>\n";
}
</programlisting>
</informalexample>
�U�����d�Ҥ]�O�@�˥\�:
<informalexample>
<programlisting role="php">
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>
��h���ܽd:
<informalexample>
<programlisting role="php">
/* 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";
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.break">
<title><literal>break</literal></title>
<simpara>
break �O�ΨӸ��������U�C���j��α���y�� �G if �B for �B while�Bswitch �C
</simpara>
<simpara>
�� break �ɥi�H�[�W�@�ӰѼƧi�D�q���n�����h�ּh���j��C </simpara>
<para>
<informalexample>
<programlisting role="php">
$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>
continue �b�j�餤���@�άO�߮ɸ����{�ɰ��椤���`���Ӷ}�l�U�@�Ӵ`���C
</simpara>
<simpara>
continue �M break �@�˥i�Τ@�ӰѼƫ��ܥ����ӱq���@�h�j��}�l�U�@���`���C
</simpara>
<para>
<informalexample>
<programlisting role="php">
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>
switch �R�O���\��M�@�s��ΦP�@������F���� if �y�y�ۦ��C
�����֪����p�n�D��@���ܼƩΤ@�y���F���M���P���ƭȧ@����A
��������Y�@�ӼƭȮɫK����۹������{���q�C �o���O switch ���\�ΡC
</simpara>
<para>
�U���ܽd�F��˥Τ@�s�ꪺ if �M�Τ@�� switch �ӧ����ۦP���u�@�G <informalexample>
<programlisting role="php">
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>
���F�קK�˿��A�̦n�O�d���� switch ���B�@�覡�C switch �O�@�y���@�y������{�����C ����
PHP �n��@��case ���ȩM switch ������F���Һt��X�Ӫ��ȬO�@�˪��C �M�� PHP
�|����b���� case ����X�{���Ҧ����O���� switch �{���q���̫�Ϊ̪��� PHP �I��@�y
break ���O�C �p�G�A�S���b�C�� case ���̫�[�W break ���O�A PHP
�|���U�h���汵�b�U�����t�@�� case ���������O�I �U�����{���ܽd�F�o�@�I�G
<informalexample>
<programlisting role="php">
switch ($i) {
case 0:
print "i equals 0";
case 1:
print "i equals 1";
case 2:
print "i equals 2";
}
</programlisting>
</informalexample>
</para>
<simpara>
��W���{���Ө��A �p�G $i �O 0 ���ܡA PHP �|����Ҧ��� print ���O�I �p�G $i �O 1�A PHP
�u�|����᭱��y���O�F �u���� $i �� 2 �~�|�o�쥻�ӷQ�n�����G�G�L�X 'i equals 2' �C
�Ѧ��i���A ���U�O�n�|�F�� break ���O�b�C�� case ����C (���M�b�@�DZ��p�U�A�i��S�a���[
break�C)
</simpara>
<simpara>
�{������ switch �ɡA ������F���u�|�Q�ˬd�@���C �o�@�����B��G�|�ΨөM�C�� case
����F ���b elseif �y�y���ӱ�����F���|���s�Q�t��@�M�C
�]���b������F���ܽ����άO�b�t�n�D�ܰ����j�餤�� switch �|����֤@�ǡC
</simpara>
<para>
�@�� case �ҧt�����O�ƥؤ]�i�H�O 0 �ӡA �o�ˤ@�ӵ{���|�۰��ˬd�U�@�� case
<informalexample>
<programlisting role="php">
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>
���ӯS���� case �O default case�A �p�G�Ҧ��� case ���S�k���߮ɡA default �K�|�Q����C
�ݤU�����ܽd:
<informalexample>
<programlisting role="php">
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>
���Ī� case ���F���@�w�n�o�X�@������²�檺�ƭȡA �p��ơB �p�ƩάO��y�C
�p�G�O�}�C���ܴN�@�w�n���X�}�C�������@�Ӥ����øӤ����]�n�O�@������²�檺�ȡC
</para>
<para>
swithes �]�����̥t�@�ص��Ī��g�k�A �Ա��i�� <link
linkend="control-structures.alternative-syntax">����{���y�{�����ĥy�k </link> .
<informalexample>
<programlisting role="php">
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="function.require">
<title><function>require</function></title>
<simpara>
The <function>require</function> statement replaces itself with
the specified file, much like the C preprocessor's
<literal>#include</literal> works.
</simpara>
<simpara>
If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be
<function>require</function>ed using an URL instead of a local
pathname. See <link linkend="features.remote-files">Remote
files</link> and <function>fopen</function> for more information.
</simpara>
<simpara>
An important note about how this works is that when a file is
<function>include</function>ed or <function>require</function>ed,
parsing drops out of PHP mode and into HTML mode at the beginning
of the target file, and resumes PHP mode again at the end. For
this reason, any code inside the target file which should be
executed as PHP code must be enclosed within <link
linkend="language.basic-syntax.phpmode">valid PHP start and end
tags</link>.
</simpara>
<simpara>
<function>require</function> is not actually a function in PHP;
rather, it is a language construct. It is subject to some
different rules than functions are. For instance,
<function>require</function> is not subject to any containing
control structures. For another, it does not return any value;
attempting to read a return value from a
<function>require</function> call results in a parse error.
</simpara>
<simpara>
Unlike <function>include</function>, <function>require</function>
will <emphasis>always</emphasis> read in the target file,
<emphasis>even if the line it's on never executes</emphasis>. If
you want to conditionally include a file, use
<function>include</function>. The conditional statement won't
affect the <function>require</function>. However, if the line on
which the <function>require</function> occurs is not executed,
neither will any of the code in the target file be executed.
</simpara>
<simpara>
Similarly, looping structures do not affect the behaviour of
<function>require</function>. Although the code contained in the
target file is still subject to the loop, the
<function>require</function> itself happens only once.
</simpara>
<para>
This means that you can't put a <function>require</function>
statement inside of a loop structure and expect it to include the
contents of a different file on each iteration. To do that, use an
<function>include</function> statement.
<informalexample>
<programlisting role="php">
require ('header.inc');
</programlisting>
</informalexample>
</para>
<simpara>
When a file is <function>require</function>ed, the code it
contains inherits the variable scope of the line on which the
<function>require</function> occurs. Any variables available at
that line in the calling file will be available within the called
file. If the <function>require</function> occurs inside a
function within the calling file, then all of the code contained
in the called file will behave as though it had been defined
inside that function.
</simpara>
<para>
If the <function>require</function>ed file is called via HTTP
using the fopen wrappers, and if the target server interprets the
target file as PHP code, variables may be passed to the
<function>require</function>ed file using an URL request string as
used with HTTP GET. This is not strictly speaking the same thing
as <function>require</function>ing the file and having it inherit
the parent file's variable scope; the script is actually being run
on the remote server and the result is then being included into
the local script.
<informalexample>
<programlisting role="php">
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the require()ed file. */
/* Won't work; file.txt wasn't handled by someserver. */
require ("http://someserver/file.txt?varone=1&vartwo=2");
/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
require ("file.php?varone=1&vartwo=2");
/* Works. */
require ("http://someserver/file.php?varone=1&vartwo=2");
$varone = 1;
$vartwo = 2;
require ("file.txt"); /* Works. */
require ("file.php"); /* Works. */
</programlisting>
</informalexample>
</para>
<simpara>
In PHP 3, it is possible to execute a <literal>return</literal>
statement inside a <function>require</function>ed file, as long as
that statement occurs in the global scope of the
<function>require</function>ed file. It may not occur within any
block (meaning inside braces ({}). In PHP 4, however, this ability
has been discontinued. If you need this functionality, see
<function>include</function>.
</simpara>
<simpara>
See also <function>include</function>, <function>require_once</function>,
<function>include_once</function>, <function>readfile</function>,
and <function>virtual</function>.
</simpara>
</sect1>
<sect1 id="function.include">
<title><function>include</function></title>
<simpara>
The <function>include</function> statement includes and evaluates
the specified file.
</simpara>
<simpara>
If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be
<function>include</function>ed using an URL instead of a local
pathname. See <link linkend="features.remote-files">Remote
files</link> and <function>fopen</function> for more information.
</simpara>
<simpara>
An important note about how this works is that when a file is
<function>include</function>ed or <function>require</function>ed,
parsing drops out of PHP mode and into HTML mode at the beginning
of the target file, and resumes again at the end. For this reason,
any code inside the target file which should be executed as PHP
code must be enclosed within <link
linkend="language.basic-syntax.phpmode">valid PHP start and end
tags</link>.
</simpara>
<para>
This happens each time the <function>include</function> statement
is encountered, so you can use an <function>include</function>
statement within a looping structure to include a number of
different files.
<informalexample>
<programlisting role="php">
$files = array ('first.inc', 'second.inc', 'third.inc');
for ($i = 0; $i < count($files); $i++) {
include $files[$i];
}
</programlisting>
</informalexample>
</para>
<para>
<function>include</function> differs from
<function>require</function> in that the include statement is
re-evaluated each time it is encountered (and only when it is
being executed), whereas the <function>require</function>
statement is replaced by the required file when it is first
encountered, whether the contents of the file will be evaluated or
not (for example, if it is inside an <link
linkend="control-structures.if">if</link> statement whose
condition evaluated to false).
</para>
<para>
Because <function>include</function> is a special language
construct, you must enclose it within a statement block if it is
inside a conditional block.
<informalexample>
<programlisting role="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>
</informalexample>
</para>
<simpara>
In both PHP 3 and PHP 4, it is possible to execute a
<literal>return</literal> statement inside an
<function>include</function>ed file, in order to terminate
processing in that file and return to the script which called
it. Some differences in the way this works exist, however. The
first is that in PHP 3, the <literal>return</literal> may not
appear inside a block unless it's a function block, in which case
the <literal>return</literal> applies to that function and not the
whole file. In PHP 4, however, this restriction does not
exist. Also, PHP 4 allows you to return values from
<function>include</function>ed files. You can take the value of
the <function>include</function> call as you would a normal
function. This generates a parse error in PHP 3.
</simpara>
<example>
<title><function>include</function> in PHP 3 and PHP 4</title>
<para>
Assume the existence of the following file (named
<filename>test.inc</filename>) in the same directory as the main
file:
<programlisting role="php">
<?php
echo "Before the return <br>\n";
if (1) {
return 27;
}
echo "After the return <br>\n";
?>
</programlisting>
</para>
<para>
Assume that the main file (<filename>main.html</filename>)
contains the following:
<programlisting role="php">
<?php
$retval = include ('test.inc');
echo "File returned: '$retval'<br>\n";
?>
</programlisting>
</para>
<para>
When <filename>main.html</filename> is called in PHP 3, it will
generate a parse error on line 2; you can't take the value of an
<function>include</function> in PHP 3. In PHP 4, however, the
result will be:
<screen>
Before the return
File returned: '27'
</screen>
</para>
<para>
Now, assume that <filename>main.html</filename> has been altered
to contain the following:
<programlisting role="php">
<?php
include ('test.inc');
echo "Back in main.html<br>\n";
?>
</programlisting>
</para>
<para>
In PHP 4, the output will be:
<screen>
Before the return
Back in main.html
</screen>
However, PHP 3 will give the following output:
<screen>
Before the return
27Back in main.html
Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5
</screen>
</para>
<para>
The above parse error is a result of the fact that the
<literal>return</literal> statement is enclosed in a non-function
block within <filename>test.inc</filename>. When the return is
moved outside of the block, the output is:
<screen>
Before the return
27Back in main.html
</screen>
</para>
<para>
The spurious '27' is due to the fact that PHP 3 does not support
<literal>return</literal>ing values from files like that.
</para>
</example>
<simpara>
When a file is <function>include</function>ed, the code it
contains inherits the variable scope of the line on which the
<function>include</function> occurs. Any variables available at
that line in the calling file will be available within the called
file. If the <function>include</function> occurs inside a
function within the calling file, then all of the code contained
in the called file will behave as though it had been defined
inside that function.
</simpara>
<para>
If the <function>include</function>ed file is called via HTTP
using the fopen wrappers, and if the target server interprets the
target file as PHP code, variables may be passed to the
<function>include</function>ed file using an URL request string as
used with HTTP GET. This is not strictly speaking the same thing
as <function>include</function>ing the file and having it inherit
the parent file's variable scope; the script is actually being run
on the remote server and the result is then being included into
the local script.
<informalexample>
<programlisting role="php">
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the include()ed file. */
/* Won't work; file.txt wasn't handled by someserver. */
include ("http://someserver/file.txt?varone=1&vartwo=2");
/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
include ("file.php?varone=1&vartwo=2");
/* Works. */
include ("http://someserver/file.php?varone=1&vartwo=2");
$varone = 1;
$vartwo = 2;
include ("file.txt"); /* Works. */
include ("file.php"); /* Works. */
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>require</function>, <function>require_once</function>,
<function>include_once</function>, <function>readfile</function>,
and <function>virtual</function>.
</simpara>
</sect1>
<sect1 id="function.require-once">
<title><function>require_once</function></title>
<para>
The <function>require_once</function> statement replaces
itself with the specified file, much like the C preprocessor's
<literal>#include</literal> works, and in that respect is
similar to the <function>require</function> statement. The main
difference is that in an inclusion chain, the use of
<function>require_once</function> will assure that the code is
added to your script only once, and avoid clashes with variable
values or function names that can happen.
</para>
<para>
For example, if you create the following 2 include files
<literal>utils.inc</literal> and <literal>foolib.inc</literal>
<example>
<title>utils.inc</title>
<programlisting role="php">
<?php
define(PHPVERSION, floor(phpversion()));
echo "GLOBALS ARE NICE\n";
function goodTea() {
return "Oolong tea tastes good!";
}
?>
</programlisting>
</example>
<example>
<title>foolib.inc</title>
<programlisting role="php">
<?php
require ("utils.inc");
function showVar($var) {
if (PHPVERSION == 4) {
print_r($var);
} else {
var_dump($var);
}
}
// bunch of other functions ...
?>
</programlisting>
</example>
And then you write a script <literal>cause_error_require.php</literal>
<example>
<title>cause_error_require.php</title>
<programlisting role="php">
<?php
require("foolib.inc");
/* the following will generate an error */
require("utils.inc");
$foo = array("1",array("complex","quaternion"));
echo "this is requiring utils.inc again which is also\n";
echo "required in foolib.inc\n";
echo "Running goodTea: ".goodTea()."\n";
echo "Printing foo: \n";
showVar($foo);
?>
</programlisting>
</example>
When you try running the latter one, the resulting ouptut will be (using
PHP 4.01pl2):
<informalexample>
<programlisting>
GLOBALS ARE NICE
GLOBALS ARE NICE
Fatal error: Cannot redeclare goodTea() in utils.inc on line 5
</programlisting>
</informalexample>
By modifying <literal>foolib.inc</literal> and
<literal>cause_errror_require.php</literal>
to use <function>require_once</function>
instead of <function>require</function> and renaming the
last one to <literal>avoid_error_require_once.php</literal>, we have:
<example>
<title>foolib.inc (fixed)</title>
<programlisting role="php">
..
require_once("utils.inc");
function showVar($var) {
..
</programlisting>
</example>
<example>
<title>avoid_error_require_once.php</title>
<programlisting role="php">
..
require_once("foolib.inc");
require_once("utils.inc");
$foo = array("1",array("complex","quaternion"));
..
</programlisting>
</example>
And when running the latter, the output will be (using PHP 4.0.1pl2):
<informalexample>
<programlisting>
GLOBALS ARE NICE
this is requiring globals.inc again which is also
required in foolib.inc
Running goodTea: Oolong tea tastes good!
Printing foo:
Array
(
[0] => 1
[1] => Array
(
[0] => complex
[1] => quaternion
)
)
</programlisting>
</informalexample>
</para>
<para>
Also note that, analogous to the behavior of the
<literal>#include</literal> of the C preprocessor, this statement
acts at "compile time", e.g. when the script is parsed and before it
is executed, and should not be used for parts of the script that need
to be inserted dynamically during its execution. You should use
<function>include_once</function> or <function>include</function>
for that purpose.
</para>
<para>
For more examples on using <function>require_once</function> and
<function>include_once</function>, look at the PEAR code included in
the latest PHP source code distributions.
</para>
<para>
See also: <function>require</function>,
<function>include</function>, <function>include_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
and <function>virtual</function>.
</para>
</sect1>
<sect1 id="function.include-once">
<title><function>include_once</function></title>
<para>
The <function>include_once</function> statement includes and evaluates
the specified file during the execution of the script.
This is a behavior similar to the <function>include</function> statement,
with the important difference that if the code from a file has already
been included, it will not be included again.
</para>
<para>
As mentioned in the <function>require_once</function> description, the
<function>include_once</function> should be used in the cases in which
the same file might be included and evaluated more than once during a
particular execution of a script, and you want to be sure that it is
included exactly once to avoid problems with function redefinitions,
variable value reassignments, etc.
</para>
<para>
For more examples on using <function>require_once</function> and
<function>include_once</function>, look at the PEAR code included in
the latest PHP source code distributions.
</para>
<para>
<function>include_once</function> was added in PHP 4.0.1pl2
</para>
<para>
See also: <function>require</function>,
<function>include</function>, <function>require_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
and <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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
<!-- Keep this comment for vi/vim/gvim
vi: et:ts=1:sw=1
-->
Index: phpdoc/hk/language/expressions.xml
+++ phpdoc/hk/language/expressions.xml
<chapter id="language.expressions">
<title>���F��</title>
<simpara>
���F���O PHP �{�����̮ڥ����զ������C �� PHP
�s�{�A�X�G�Ҧ��A�g�o�U�Ӫ����O�y���O���F���C �γ�²��B�̺�T���y�l�Ӵy�z���F���N�O�G
"���Ȫ��F��"�C
</simpara>
<simpara>
�̰����F���O�`�ƩM�ܼơC���A��J "$a = 5"�A �A�� '5' ������ $a�C '5'�A
���M�N���ƭ� 5�A �����ӻ��k�O '5' �O�@�Ӫ��F���A �����ȬO 5�C(�b���Ҥ��A '5'
�O�@�Ӿ�ƧκA���`��).
</simpara>
<simpara>
�o�ӫ����ާ@������A $a ���Ȥ]���ӬO 5�A ���p�A�A�g $b = $a�A�����X�����G���өM�g
$b = 5 �O�@�˪��C ���ӻ��k�A $a �]�@�Ӫ��F���A �����F���ȦP�ˬO 5�C
�p�G�S�������ܡA �o�X�����G�N�O�o�ӡC
</simpara>
<para>
�����������F���i�H�Ψ�ƨӧ@�ܽd�C �p�H�U���Ҥl�A
<informalexample>
<programlisting>
function foo () {
return 5;
}
</programlisting>
</informalexample></para>
<simpara>
�p�A�������Φ��@�w�{�� (�p�_�Ьݦ�����ƪ����`)�A �A�|�P�N$c = foo() �M $c = 5
�o��y�O�@�˪��C �ƹ�W���O�o�ˡC ��Ƥ]�O�@�ت��F���A
���̩Ҫ��F���ȴN�O��ƪ��B��G(�Ǧ^��)�C �]�� foo() �Ǧ^ 5�A �ҥH���F�� 'foo()'
���ȴN�O 5�C ���M�@��ӻ���Ƥ��|���Ǧ^�@�ӱ`�ƦӬO�n�@�ǹB�⪺�C
</simpara>
<simpara>
���M�A �Ȥ��@�w�O��ơC PHP �i�H���A���ΤT�ؤ��P���Ϊ��¶q�ȡA
���O�O��ơB�B�I�ơB��y�C(�¶q�ȴN�O����A������p�����q���ȡA�D�¶q�Ȫ��Ҥl���ڶq�A�}�C��)�C�t�~
PHP �]�䴩�}�C�M��������D�¶q�ȡC
�q��ƶǦ^���Ȫ��κA�M�������ܼƪ��Ȫ��κA�i�H�O�W�z������@�حȡC
</simpara>
<simpara>
��ثe����A �� PHP/FI 2 ���H�����|ı�o�����@�ˡC �M�ӡA PHP
����F���������i�@�B�o���A �ܦ��M�ܦh�O���{���y���@�ˡC PHP
�O�H���F������¦���s�{�y���A �o�˻��O�]���X�G�Ҧ� PHP ���y�l���O�Ѫ��F���զ��C
���R�W���ιL���Ҥl '$a = 5'�A�ܩ��㪺�b�ާ@�����ⶵ�ȡA �@���O��� '5'�A �t�@���O $a
���ȡA ���|�Q '5' �Ҩ��N�C ���L����٦��t�@�ӭȦs�b�A���N�O���F�������Ҫ��F���ȡC
�b���Ҥ����F�����ȴN�O���N�ȡA �]�N�O '5'�E ���Ϊ��ɭԧڭ̥i�H�� '$a=5' �ݦ��O�ӶǦ^
'5' �o�ӭȪ����F���C �Ѧ��A �p�G�A�g '$b = ($a = 5)' �N���P��g '$a = 5; $b = 5;'
(�����N���y�y������)�C �A�i�@�B���A �]�����F���O�q�k�V���Ӱ��B�⪺�A
�ҥH�N��²�檺�g�� '$b = $a = 5'�A ���פ]�O�@�˪��C
</simpara>
<simpara>
�H���F�������ާ@�٦��t�~�@�ثܦn���ܨҡC �N�O�e�m�Ϋ�m���W�ȩM�l�Ⱦާ@�C �ϥ�
PHP/FI 2 �M�\�h��L�y�����{�����j���w�ݺD�F �ܼ�++ �M �ܼ�-- �����F�y���C
�o�ǫK�O�W�ȩM�l�ȹB��šC �b PHP/FI 2 ���ɭԡA '$a++' �ä��N�������
(�ä��O�@�Ӫ��F��)�A �]���W�A����Υ��Ӱ��O���ơC ��F PHP�A
�o�ǥy�����ܦ��F���F�� (�N�� C �@��)�C �t�~�M C �ۦP���O�A ����ؼW�Ⱥ�šG
�e�m���M��m���C ��س��|���ܼƼW�[ 1�A ���O�b�����F���Ҫ��F���ȡC �e�m���O�g��
'++$variable'�A �Ǧ^���O�W�ȫ᪺�ȡF (PHP �bŪ�����F�����Ȥ��e�����ܼƭȥ[ 1�A
�]���s�e�m) ��m���F���g�� '$variable++' �Ǧ^�ܼ��٨S�W�[ 1 �e���� (PHP
Ū�������F�����Ȥ���~���ܼƼW��)�C
</simpara>
<simpara>
������O�@�ط����`�������F���C �o�����F�����B��G�O 1 �� 0�A ���O�N����� �u �M
���C PHP ���� > (�j��)�F >= (�j����)�F == (����)�F != (������)�F <
(�p��)�F <= (�p��ε���)�C �o�����F���q�`�Φb����y�����A �pif �y�y�C
</simpara>
<simpara>
�̫�@�ӥܽd�ڭ̷|����@���P�ɰ������M�B�⪺���F���C �A�w���D�p�G�Q�� $a �W�[ 1�A
�i�H������ '$a++' �� '++$a'�C ���O�p�G�A���O�Q�� $a �W�[�h�@�ǡA ��p�� '3'
���ӫ�˰��@�H ���M�i�H�s�g 3 ��'$a++'�A ���L�o�ܤ��n�ݡC �����������k�O��
'$a=$a+3;'�G '$a + 3' �����F���O $a �A�[�W 3�A �o���G�|��^�ܼ� $a �����A
��ӹB�⧹���� $a �����e�|�W�[�F 3�C �� PHP
�M�\�h��L�y���P�˥i�H�⦹���ާ@�g���t�@�Ӹ�²�檺�y���A�N�ӳo�إy�k�i��|��y��]����z�ѡC
�� $a ���ȼW�[ 3 �i�g�� '$a += 3'. ���N�����N���F�� $a ���Ȯ��X�ӡA �W�[ 3�A �A�s�^
$a �����C���F��u�M����դ��~�A �o�y������_�Ӥ]��֡C �o�y���F���Ǧ^���ȩM�Q��
regular expr �ɤ@�ˡA �O���F���B�⪺���G '$a+3'�C
����@�ӻݭn��ӹB�⤸���B��ų��i�Φ����y���y�y�A �Ҧp '$a -= 5' (�� $a �� 5), '$b *=
7' (�� $b ���H 7) ���C
</simpara>
<para>
�t�~���@�جݰ_�Ӥ���Ǧ��O�b��L���{���y�����]�|�Ψ쪺���F��: (ternary conditional
operator �T���B�⦡)
<informalexample><programlisting>
$first ? $second : $third
</programlisting></informalexample>
���Ĥ@�Ӫ��F�������߮ɡA �ĤG�Ӫ��F�����|�Q����ӹB��G�|������Ӫ��F�����ȡC
���Ĥ@�Ӫ��F���������߮ɡA �ĤT�Ӥ��������G�|������Ӫ��F�����ȡC
</para>
<para>
�H�U���ܽd�|���A��n�a�x���e�m�M��m�W�ȹB��ũM���F�����B��:
<informalexample>
<programlisting>
function double($i) {
return $i*2;
}
$b = $a = 5; /* assign the value five into the variable $a and $b */
$c = $a++; /* post-increment, assign original value of $a
(5) to $c */
$e = $d = ++$b; /* pre-increment, assign the incremented value of
$b (6) to $d and $e */
/* at this point, both $d and $e are equal to 6 */
$f = double($d++); /* assign twice the value of $d <emphasis>before</emphasis>
the increment, 2*6 = 12 to $f */
$g = double(++$e); /* assign twice the value of $e <emphasis>after</emphasis>
the increment, 2*7 = 14 to $g */
$h = $g += 10; /* first, $g is incremented by 10 and ends with the
value of 24. the value of the assignment (24) is
then assigned into $h, and $h ends with the value
of 24 as well. */
</programlisting></informalexample></para>
<simpara>
�b�����}�l�ɧڭ̻��|����y�y statment �������C ���F���i�H�O�y�y�A
���ëD���������F�N���O�y�y�C �b�W�Ҥ��A �y�y���Φ��O 'expr' ';' �A
�N�O�@�����F���[�W�����C ��p '$b=$a=5;'�A $a=5 �O�@�ӦX�k�����F�������O�@�y�y�y�C ��
'$b=$a=5;' �ˬO�@�y�X�k���y�y�C
</simpara>
<simpara>
�̫�Ȫ��@�����O���F������ȡC�\�h���p�U�A �ר�O����y�M�j��y�ءA
���F�����Ȩä��O���I�ϦӸӪ��F���O�_���� ( TRUE �٬O FALSE)�C (PHP
�èS���S�O���w���ܼ����C) ���F�����u���Ȫ��p���k�M perl �t���h�C ������ 0
���Ʀr���N���u�A 0 �h�N�����C ���߭t�Ʀ]���]���� 0 �A �ҥH�]�N���u�I �Ū���y�Τ�y
"0" �O���A �Ҧ���L��y���O�u�C �ܩ}�C�M����o�˪��D�¶q�ȡA
�p�G���G�O�Ū��}�C�h�N���u�A �Ϥ��h�O���C
</simpara>
<simpara>
PHP ���ѤF����ӥB�\��j�j�����F���C
����U�S�i���Ҧ��i�Ϊ����F�����y�k�βξ�z�����A
���W�����ܽd���i���A���D�y�y����k�C �b����U�����A �ڭ̷|�� expr �ӥN���X�k�����F���C
</simpara>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/functions.xml
+++ phpdoc/hk/language/functions.xml
<chapter id="functions">
<title>Functions</title>
<sect1 id="functions.user-defined">
<title>User-defined functions</title>
<para>
A function may be defined using syntax such as the following:
<informalexample>
<programlisting role="php">
function foo ($arg_1, $arg_2, ..., $arg_n) {
echo "Example function.\n";
return $retval;
}
</programlisting>
</informalexample>
</para>
<simpara>
Any valid PHP code may appear inside a function, even other
functions and <link linkend="keyword.class">class</link>
definitions.
</simpara>
<simpara>
In PHP 3, functions must be defined before they are referenced. No
such requirement exists in PHP 4.
</simpara>
<simpara>
PHP does not support function overloading, nor is it possible to
undefine or redefine previously-declared functions.
</simpara>
<simpara>
PHP 3 does not support variable numbers of arguments to functions,
although default arguments are supported (see <link
linkend="functions.arguments.default">Default argument
values</link> for more information). PHP 4 supports both: see <link
linkend="functions.variable-arg-list">Variable-length argument
lists</link> and the function references for
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> for more information.
</simpara>
</sect1>
<sect1 id="functions.arguments">
<title>Function arguments</title>
<simpara>
Information may be passed to functions via the argument list,
which is a comma-delimited list of variables and/or constants.
</simpara>
<para>
PHP supports passing arguments by value (the default), <link
linkend="functions.arguments.by-reference">passing by
reference</link>, and <link
linkend="functions.arguments.default">default argument
values</link>. Variable-length argument lists are supported only
in PHP 4 and later; see <link
linkend="functions.variable-arg-list">Variable-length argument
lists</link> and the function references for
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> for more information. A
similar effect can be achieved in PHP 3 by passing an array of
arguments to a function:
<informalexample>
<programlisting role="php">
function takes_array($input) {
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
</programlisting>
</informalexample>
</para>
<sect2 id="functions.arguments.by-reference">
<title>Making arguments be passed by reference</title>
<simpara>
By default, function arguments are passed by value (so that if
you change the value of the argument within the function, it does
not get changed outside of the function). If you wish to allow a
function to modify its arguments, you must pass them by
reference.
</simpara>
<para>
If you want an argument to a function to always be passed by
reference, you can prepend an ampersand (&) to the argument
name in the function definition:
<informalexample>
<programlisting role="php">
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
</programlisting>
</informalexample>
</para>
<para>
If you wish to pass a variable by reference to a function which
does not do this by default, you may prepend an ampersand to the
argument name in the function call:
<informalexample>
<programlisting role="php">
function foo ($bar) {
$bar .= ' and something extra.';
}
$str = 'This is a string, ';
foo ($str);
echo $str; // outputs 'This is a string, '
foo (&$str);
echo $str; // outputs 'This is a string, and something extra.'
</programlisting>
</informalexample>
</para>
</sect2>
<sect2 id="functions.arguments.default">
<title>Default argument values</title>
<para>
A function may define C++-style default values for scalar
arguments as follows:
<informalexample>
<programlisting role="php">
function makecoffee ($type = "cappucino") {
return "Making a cup of $type.\n";
}
echo makecoffee ();
echo makecoffee ("espresso");
</programlisting>
</informalexample>
</para>
<para>
The output from the above snippet is:
<screen>
Making a cup of cappucino.
Making a cup of espresso.
</screen>
</para>
<simpara>
The default value must be a constant expression, not (for
example) a variable or class member.
</simpara>
<para>
Note that when using default arguments, any defaults should be on
the right side of any non-default arguments; otherwise, things
will not work as expected. Consider the following code snippet:
<informalexample>
<programlisting role="php">
function makeyogurt ($type = "acidophilus", $flavour) {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // won't work as expected
</programlisting>
</informalexample>
</para>
<para>
The output of the above example is:
<screen>
Warning: Missing argument 2 in call to makeyogurt() in
/usr/local/etc/httpd/htdocs/php3test/functest.html on line 41
Making a bowl of raspberry .
</screen>
</para>
<para>
Now, compare the above with this:
<informalexample>
<programlisting role="php">
function makeyogurt ($flavour, $type = "acidophilus") {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // works as expected
</programlisting>
</informalexample>
</para>
<para>
The output of this example is:
<screen>
Making a bowl of acidophilus raspberry.
</screen>
</para>
</sect2>
<sect2 id="functions.variable-arg-list">
<title>Variable-length argument lists</title>
<simpara>
PHP 4 has support for variable-length argument lists in
user-defined functions. This is really quite easy, using the
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> functions.
</simpara>
<simpara>
No special syntax is required, and argument lists may still be
explicitly provided with function definitions and will behave as
normal.
</simpara>
</sect2>
</sect1>
<sect1 id="functions.returning-values">
<title>Returning values</title>
<para>
Values are returned by using the optional return statement. Any
type may be returned, including lists and objects.
<informalexample>
<programlisting role="php">
function square ($num) {
return $num * $num;
}
echo square (4); // outputs '16'.
</programlisting>
</informalexample>
</para>
<para>
You can't return multiple values from a function, but similar
results can be obtained by returning a list.
<informalexample>
<programlisting role="php">
function small_numbers() {
return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
</programlisting>
</informalexample>
</para>
<para>
To return a reference from a function, you have to use
the reference operator & in both the function declaration and
when assigning the returned value to a variable:
<informalexample>
<programlisting role="php">
function &returns_reference() {
return $someref;
}
$newref =&returns_reference();
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="functions.old-syntax">
<title><literal>old_function</literal></title>
<simpara>
The <literal>old_function</literal> statement allows you to
declare a function using a syntax identical to PHP/FI2 (except you
must replace 'function' with 'old_function'.
</simpara>
<simpara>
This is a deprecated feature, and should only be used by the
PHP/FI2->PHP 3 convertor.
</simpara>
<warning>
<para>
Functions declared as <literal>old_function</literal> cannot be
called from PHP's internal code. Among other things, this means
you can't use them in functions such as
<function>usort</function>, <function>array_walk</function>, and
<function>register_shutdown_function</function>. You can get
around this limitation by writing a wrapper function (in normal
PHP 3 form) to call the <literal>old_function</literal>.
</para>
</warning>
</sect1>
<sect1 id="functions.variable-functions">
<title>Variable functions</title>
<para>
PHP supports the concept of variable functions. This means that if
a variable name has parentheses appended to it, PHP will look for
a function with the same name as whatever the variable evaluates
to, and will attempt to execute it. Among other things, this can
be used to implement callbacks, function tables, and so forth.
</para>
<para>
<example>
<title>Variable function example</title>
<programlisting role="php">
<?php
function foo() {
echo "In foo()<br>\n";
}
function bar( $arg = '' ) {
echo "In bar(); argument was '$arg'.<br>\n";
}
$func = 'foo';
$func();
$func = 'bar';
$func( 'test' );
?>
</programlisting>
</example>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/oop.xml
+++ phpdoc/hk/language/oop.xml
<chapter id="language.oop">
<title>���O�M����</title>
<sect1 id="keyword.class">
<title><literal>���O</literal></title>
<para>
���O������²��ӻ��N�O�@�p�q(�]�i��O�@�j�q)���@�ӦW�٪��{���q�A
�䤺���ܼƥH�Ψϥγo���ܼƪ���ơC �w�q���O���y�k�ЬݤU�C�ܽd�G
<informalexample>
<programlisting role="php">
<?php
class Cart {
var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item ($artnr, $num) {
$this->items[$artnr] += $num;
}
// Take $num articles of $artnr out of the cart
function remove_item ($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} else {
return false;
}
}
}
?>
</programlisting>
</informalexample>
</para>
<para>
�W���w�q�F�@�ӥs�� Cart �����O(��: �������W�ʪ���)�C
���]�A�F�@�ӦW�ٯ��ަ����}�C�H��Ӥ��O�ΨӦb�}�C���[�J�Φ������~����ơC
</para>
<note>
<simpara>
In PHP 4, only constant initializers for <literal>var</literal>
variables are allowed. Use constructors for non-constant
initializers.
</simpara>
<informalexample>
<programlisting role="php">
/* None of these will work in PHP 4. */
class Cart {
var $todays_date = date("Y-m-d");
var $name = $firstname;
var $owner = 'Fred ' . 'Jones';
}
/* This is how it should be done. */
class Cart {
var $todays_date;
var $name;
var $owner;
function Cart() {
$this->todays_date = date("Y-m-d");
$this->name = $GLOBALS['firstname'];
/* etc. . . */
}
}
</programlisting>
</informalexample>
</note>
<para>
���O�O�@���ܼƪ��κA�C �]�N�O���� integer�B string ����H��Y���O�κA�������ܼơC
���P���O�إ߬Y�����O���ܼƻݭn�Ψ� new ���O (��:
�o�˲��ͪ��ܼƳN�y�W�s���إߤF�@�Ӫ���)�G
</para>
<informalexample>
<programlisting role="php">
$cart = new Cart;
$cart->add_item("10", 1);
</programlisting>
</informalexample>
<para>
�W�ҫإߤF�@�ӥs�� cart ������A �������O�O $Cart�C (�ٰO�o PHP
���j�p�g�O���@�˪��� ?) ��۽եθӪ��� add_item ��Ʀb�}�C���[�J�@�ӽs�� '10'
���F��C
</para><para> ���O�]�i�H�O��L���O�������C
�s�����O�~�ӤF�ª����O���~�٥i�H�[�W�ۤv���ܼƤΥ\��C
�w�q�������O����k�O�w�q���O�ɥ[�W extend �o������r�C ���L���ǩw�h���~�����Y�C
</para>
<informalexample>
<programlisting role="php">
class Named_Cart extends Cart {
var $owner;
function set_owner ($name) {
$this->owner = $name;
}
}
</programlisting>
</informalexample>
<para>
�W���s�w�q�F Named_Cart ���O�A ���֦� Cart
���O���Ҧ����ܼƤΨ�ƥt�[�W�@�Ӧs�Τ�W�r���ܼƤΦs�����ܼƪ���ơG set_owner()�C
�A�i�ΦѤ�k�ھڷs���O�إߤ@�Ӫ���A
�{�b�o�Ӫ��F�i�H���H�e�@�˥[��F��~�٥i�H�]�w�Τ�W�r�G
</para>
<informalexample>
<programlisting role="php">
$ncart = new Named_Cart; // Create a named cart
$ncart->set_owner ("kris"); // Name that cart
print $ncart->owner; // print the cart owners name
$ncart->add_item ("10", 1); // (inherited functionality from cart)
</programlisting>
</informalexample>
<para>
�b�w�q���O�� $this �o���ܼƬO�������C �b�����A�@�w�n�� $this->something
���y���ӽեΩΦs�������ܼƩM��ơC
�C
Both in and
outside of the object you do not need a $ when accessing an object's
properties.
</para>
<informalexample>
<programlisting role="php">
$ncart->owner = "chris"; // no $
$ncart->$owner = "chris";
// this is invalid because $ncart->$owner = $ncart->""
$myvar = 'owner';
$ncart->$myvar = "chris";
// this is valid because $ncart->$myvar = $ncart->owner
</programlisting>
</informalexample>
<para>
Constructors �سy�� �O���O�����@�Ө�ơC
���|�b�C�Ӯھڸ����O���ͪ���ɦ۰ʳQ����C
�����ܦ��سy�̨�ƪ���k�O��Ө�ƩR�W���M���O���W�r�@�ˡC
</para>
<informalexample>
<programlisting role="php">
class Auto_Cart extends Cart {
function Auto_Cart () {
$this->add_item ("10", 1);
}
}
</programlisting>
</informalexample>
<para>
�W���ڭ̩w�q�F Auto_Cart ���O�C ���O�@�� Cart ���O�[�W�F�@�ӫسy�̨�ơA
�o��Ʒ|�۰ʷ|�b�}�C (�Ϊ̻��O�ʪ���) ���[�W�@�� '10' �����F��C
�t�~�سy�̨�Ƥ]�i�H�����ѼơA �o�O�إߪ���ɦ���j���u�ʡC
</para>
<informalexample>
<programlisting role="php">
class Constructor_Cart extends Cart {
function Constructor_Cart ($item = "10", $num = 1) {
$this->add_item ($item, $num);
}
}
// Shop the same old boring stuff.
$default_cart = new Constructor_Cart;
// Shop for real...
$different_cart = new Constructor_Cart ("20", 17);
</programlisting>
</informalexample>
<caution>
<simpara>
����~�����O�Ө��A �p�G�l���O�M�����O�����سy�̨�ƸܡA
�إ��~�����O������ɨä��|�P�ɽեΥ����O���سy�̨�ơC
</simpara>
</caution>
</sect1>
<sect1 id="language.oop.newref">
<title>References inside the constructor</title>
<para>
Creating references within the constructor can lead to confusing
results. This tutorial-like section helps you to avoid problems.
<informalexample>
<programlisting role="php">
class foo {
function foo($name) {
// create a reference inside the global array $globalref
global $globalref;
$globalref[] = &$this;
// set name to passed value
$this->setName($name);
// and put it out
$this->echoName();
}
function echoName() {
echo "<br>",$this->Name;
}
function setName($name) {
$this->Name = $name;
}
}
</programlisting>
</informalexample>
</para>
<para>
Let us check out if there is a difference between <varname>$bar1</varname> which
has been created using the copy <literal>=</literal> operator
and <varname>$bar2</varname> which has been created using the reference
<literal>=&</literal> operator...
<informalexample>
<programlisting role="php">
$bar1 = new foo('set in constructor');
$bar1->echoName();
$globalref[0]->echoName();
/* output:
set in constructor
set in constructor
set in constructor */
$bar2 =& new foo('set in constructor');
$bar2->echoName();
$globalref[1]->echoName();
/* output:
set in constructor
set in constructor
set in constructor */
</programlisting>
</informalexample>
</para>
<para>
Apparently there is no difference, but in fact there is a very significant one:
<varname>$bar1</varname> and <varname>$globalref[0]</varname> are _NOT_
referenced, they are NOT the same variable.
This is because "new" does not return a reference by default, instead it returns a
copy.
<note>
<simpara>
There is no performance loss (since php 4 and up use reference counting)
returning copies instead of references.
On the contrary it is most often better to simply work with copies instead of
references, because creating
references takes some time where creating copies virtually takes no time
(unless none of them is a large array or object
and one of them gets changed and the other(s) one(s) subsequently, then it
would be wise to use references to change them
all concurrently).
</simpara>
</note>
To prove what is written above let us watch the code below.
<informalexample>
<programlisting role="php">
// now we will change the name. what do you expect?
// you could expect that both $bar and $globalref[0] change their names...
$bar1->setName('set from outside');
// as mentioned before this is not the case.
$bar1->echoName();
$globalref[0]->echoName();
/* output:
set on object creation
set from outside */
// let us see what is different with $bar2 and $globalref[1]
$bar2->setName('set from outside');
// luckily they are not only equyl, they are thesame variable
// thus $bar2->Name and $globalref[1]->Name are the same too
$bar2->echoName();
$globalref[1]->echoName();
/* output:
set from outside
set from outside */
</programlisting>
</informalexample>
</para>
<para>
Another final example, try to understand it.
<informalexample>
<programlisting role="php">
class a {
function a($i) {
$this->value = $i;
// try to figure out why we do not need a reference here
$this->b = new b($this);
}
function createRef() {
$this->c = new b($this);
}
function echoValue() {
echo "<br>","class ",get_class($this),': ',$this->value;
}
}
class b {
function b(&$a) {
$this->a = &$a;
}
function echoValue() {
echo "<br>","class ",get_class($this),': ',$this->a->value;
}
}
// try to undestand why using a simple copy here would yield
// in an undesired result in the *-marked line
$a =& new a(10);
$a->createRef();
$a->echoValue();
$a->b->echoValue();
$a->c->echoValue();
$a->value = 11;
$a->echoValue();
$a->b->echoValue(); // *
$a->c->echoValue();
/*
output:
class a: 10
class b: 10
class b: 10
class a: 11
class b: 11
class b: 11
*/
</programlisting>
</informalexample>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/operators.xml
+++ phpdoc/hk/language/operators.xml
<chapter id="language.operators">
<title>�U���B���</title>
<simpara>
</simpara>
<sect1 id="language.operators.arithmetic">
<title>��N�B���</title>
<simpara>
�ٰO�o���p�DZЪ��[����� �H �o�Ǻ�ŴN�O���˥Ϊ��C </simpara>
<table>
<title>��N�B���</title>
<tgroup cols="3">
<thead>
<row>
<entry>�ܽd
</entry>
<entry>��ŦW��</entry>
<entry>�B��G</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a + $b</entry>
<entry>�[�k Addition</entry>
<entry>$a �B$b ���M</entry>
</row>
<row>
<entry>$a - $b</entry>
<entry> ��k Subtraction </entry>
<entry>$a�B $b ���t</entry>
</row>
<row>
<entry>$a * $b</entry>
<entry> ���k Multiplication </entry>
<entry>$a �B$b ���n</entry>
</row>
<row>
<entry>$a / $b</entry>
<entry>���k Division</entry>
<entry>$a �B$b ����</entry>
</row>
<row>
<entry>$a % $b</entry>
<entry>�l�� Modulus</entry>
<entry>$a ���H $b �᪺�l��</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
The division operator ("/") returns an integer value (the result
of an integer division) if the two operands are integers (or
strings that get converted to integers) and the quotient is an
integer. If either operand is a floating-point value, or the
operation results in a non-integer value, a floating-point value
is returned.
</simpara>
</sect1>
<sect1 id="language.operators.assignment">
<title>���w�ܼƪ���</title>
<simpara>
��������ŬO '='�C �n���J���D���H���o�N�� '����'�A �����O���n�� '='
���k�����Ȧs�쥪�����B�⤸�����C
</simpara>
<para>
���w�ȥ����]�O�Ӫ��F���A ���ҥN�����ȴN�O���n���w���ȡC �N�O�� "$a = 3" ���ȴN�O 3�C
�o�i�H���A�y�@�Ǧ��쪺�y�y:
<informalexample>
<programlisting role="php">
$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4.
</programlisting>
</informalexample>
</para>
<para>
�t���@���B��ŧ�p��M�������ާ@�X�Ӭ��@�C
�Ҧ����G����ų��i�H�ΦX�֪��y�������ܼƪ��ȨӰ��ާ@�P�ɧ�B��G�s�^����ܼƤ����C
�ЬݤU��:
<informalexample>
<programlisting role="php">
$a = 3;
$a += 5; // sets $a to 8, as if we had said: $a = $a + 5;
$b = "Hello ";
$b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!";
</programlisting>
</informalexample>
</para>
<para>
�`�N�������ʧ@�O��ƾڧۨ�s���ܼƤ����h�C �ާ@������s���ܼƸӪ��A�]�S�����p�C
���A�ݭn�ۤ@�ӫܤj�ܤj���}�C�ɥi��|�ݭn�������ɶ��C �b�o�譱�A PHP4
���\�A�ΰѷӪ��覡�����ܼơC �p�U���y�� $var = &$othervar;
���������ܼƳ̲׳����V�P�@����ơA �����S���A�Υ���ۼg��ƪ��ʧ@�C �`�N�b PHP3
�ɬO���X�k���C
To learn more about references, please read <link
linkend="language.references">References explained</link>.
</para>
</sect1>
<sect1 id="language.operators.bitwise">
<title>�H�줸����쪺�B���</title>
<simpara>
�줸�ާ@�B��Ť��\�A�]�w��Ƥ��Y�Ӧ줸���ȡC
</simpara>
<table>
<title>�H�줸����쪺�B���</title>
<tgroup cols="3">
<thead>
<row>
<entry>�ܽd
</entry>
<entry>�B��ŦW��</entry>
<entry>�B��G</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a & $b</entry>
<entry>And</entry>
<entry>�� $a �M $b ���۹����줸�ҬO '1' �ɤ~�|�Ǧ^ 1 �C</entry>
</row>
<row>
<entry>$a | $b</entry>
<entry>Or</entry>
<entry>�� $a �M $b ���۹����줸�����@�өΥH�W '1' �ɤ~�|�Ǧ^ 1 �C/entry>
</row>
<row>
<entry>$a ^ $b</entry>
<entry>Xor</entry>
<entry>
�� $a �M $b ���۹����줸���u���@�ӬO '1' �ɤ~�|�Ǧ^ 1 �C
</entry>
</row>
<row>
<entry>~ $a</entry>
<entry>Not</entry>
<entry>
�� $a �ت��줸���ϬۡG 1 �� 0 �B 0 �� 1 �C
</entry>
</row>
<row>
<entry>$a << $b</entry>
<entry>Shift left</entry>
<entry>
�� $a ���줸�V������ $b ����h��C(�C���@���N���� $a ���H 2)
</entry>
</row>
<row>
<entry>$a >> $b</entry>
<entry>Shift right</entry>
<entry>
�� $a ���줸�V�k���� $b ����h��C(�C���@���N���� $a ���H 2)
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1 id="language.operators.comparison">
<title>�Ψӧ@������B���</title>
<simpara>
�����šA �U�W��q�O�ΨӤ����ӭȪ��j�p���C
</simpara>
<table>
<title>�Ψӧ@������B���</title>
<tgroup cols="3">
<thead>
<row>
<entry>�ܽd </entry>
<entry>��ŦW��</entry>
<entry>�B��G</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a == $b</entry>
<entry>�۵�</entry>
<entry>����̬۵��ɦ���</entry>
</row>
<row>
<entry>$a === $b</entry>
<entry>����</entry>
<entry>
����̬۵��B�κA�@�ˮɦ���(PHP4 �~��)
</entry>
</row>
<row>
<entry>$a != $b</entry>
<entry>����</entry>
<entry>����̤����ɦ���</entry>
</row>
<row>
<entry>$a !== $b</entry>
<entry>Not identical</entry>
<entry>
True if $a is not equal to $b, or they are not of the same
type. (PHP 4 only)
</entry>
</row>
<row>
<entry>$a < $b</entry>
<entry> �p�� </entry>
<entry>�e�̤p���̮ɦ���</entry>
</row>
<row>
<entry>$a > $b</entry>
<entry>�j��</entry>
<entry> ���e�̤j���̮ɦ��� /entry>
</row>
<row>
<entry>$a <= $b</entry>
<entry>�p���� </entry>
<entry>���e�̤��̤p�Ψ�̤@�ˮɦ���</entry>
</row>
<row>
<entry>$a >= $b</entry>
<entry> �j���� </entry>
<entry>���e�̤��̤j�Ψ�̤@�ˮɦ���</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
�t�@�إΨӧ@�����Ū��O "?:" (�κ٤T�� trinary) ��šC �b C
�H�Ψ�L�{���y�������i�o����šC
<informalexample>
<programlisting>
(expr1) ? (expr2) : (expr3);
</programlisting>
</informalexample>
�� expr1 ���߮ɡA �Ӻ⦡���ȵ��� expr2 �A �_�h�⦡���ȵ��� expr3 �C </para>
</sect1>
<sect1 id="language.operators.errorcontrol">
<title>����~���B���
</title>
<simpara>
PHP �u���@�Ӳα����~�����: (@)��šC �i�H�⥦�[�����@�y PHP ���O���e�A
���ɸӫ��O���p����ĵ�i�ο��~�T������ PHP �N���|�z�|�o��ĵ�i�]���|�Nĵ�i�y�l���X�ӡC
</simpara>
<simpara>
���p�]�m�F <link linkend="ini.track-errors">track_errors</link>
�ﶵ�A �Ҧ����~�H���|�Q�ۨ� $php_errormsg �ܼƤ��C �o���ܼƨä��O�}�C�A
�C�����s�����~���|���N��Ӫ��H���A �ҥH�n�Ϊ��ܭn�ɦ����ΡC
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?php
/* Intentional SQL error (extra quote): */
$res = @mysql_query ("select name, code from 'namelist") or
die ("Query failed: error was '$php_errormsg'");
?>
</programlisting>
</informalexample>
</para>
<simpara>
�t�Ь� <function>error_reporting</function>�@�`�C
</simpara>
<warning>
<para>
Currently the "@" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "@" to
suppress errors from a certain function and either it isn't
available or has been mistyped, the script will die right there
with no indication as to why.
</para>
</warning>
</sect1>
<sect1 id="language.operators.execution">
<title>�i����R�O���B���</title>
<para>
PHP �]���@�Ӱ���R�O�����: �˱��I (``)�C �d�N���ä��O����I PHP
�|������~���{���@�˰���b `` �����]�۪���y�C �p�����G��X���ܤ]�|���X�ӡC
�A�i�H�⦳������X���G�s���ܼƤ����C
<informalexample>
<programlisting role="php">
$output = `ls -al`;
echo "<pre>$output</pre>";
</programlisting>
</informalexample>
</para>
<note>
<para>
The backtick operator is disabled when <link
linkend="ini.safe-mode">safe mode</link> is enabled.
</para>
</note>
<para>
�t�Ь� <function>system</function>,
<function>passthru</function>, <function>exec</function>,
<function>popen</function>, �M <function>escapeshellcmd</function>.
</para>
</sect1>
<sect1 id="language.operators.increment">
<title>Incrementing/Decrementing �W��/�l�ȹB���
</title>
<para>
PHP �䴩 C �˦����e�m�M��m�W�l��šC
</para>
<table>
<title>Increment/decrement �W�l�B���</title>
<tgroup cols="3">
<thead>
<row>
<entry>�ܽd</entry>
<entry>��ŦW��</entry>
<entry>�@��</entry>
</row>
</thead>
<tbody>
<row>
<entry>++$a</entry>
<entry>Pre-increment �e�m�W��</entry>
<entry>���� $a �W�[ 1�A �A�Ǧ^ $a ���ȡC </entry>
</row>
<row>
<entry>$a++</entry>
<entry>Post-increment ��m�W��</entry>
<entry>���Ǧ^ $a ���ȦA�� $a �W�[ 1�C</entry>
</row>
<row>
<entry>--$a</entry>
<entry>Pre-decrement</entry>
<entry>���� $a ��h 1�A �A�Ǧ^ $a ���ȡC</entry>
</row>
<row>
<entry>$a--</entry>
<entry>Post-decrement</entry>
<entry>���Ǧ^ $a ���ȦA�� $a ��h 1�C</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
�o���²�檺�Ҥl:
<informalexample>
<programlisting role="php">
<?php
echo "<h3>Postincrement</h3>";
$a = 5;
echo "Should be 5: " . $a++ . "<br>\n";
echo "Should be 6: " . $a . "<br>\n";
echo "<h3>Preincrement</h3>";
$a = 5;
echo "Should be 6: " . ++$a . "<br>\n";
echo "Should be 6: " . $a . "<br>\n";
echo "<h3>Postdecrement</h3>";
$a = 5;
echo "Should be 5: " . $a-- . "<br>\n";
echo "Should be 4: " . $a . "<br>\n";
echo "<h3>Predecrement</h3>";
$a = 5;
echo "Should be 4: " . --$a . "<br>\n";
echo "Should be 4: " . $a . "<br>\n";
?>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="language.operators.logical">
<title>�����B���</title>
<table>
<title>�����B���</title>
<tgroup cols="3">
<thead>
<row>
<entry>�ܽd</entry>
<entry>��ŦW��</entry>
<entry> ���G </entry>
</row>
</thead>
<tbody>
<row>
<entry>$a and $b</entry>
<entry>And</entry>
<entry>�� $a�B$b ���O�u�ɦ��ߡC</entry>
</row>
<row>
<entry>$a or $b</entry>
<entry>Or</entry>
<entry> �� $a�B$b�H�K�@�ӬO�u�ɴN���ߡC </entry>
</row>
<row>
<entry>$a xor $b</entry>
<entry>Xor</entry>
<entry>�� $a�B$b �����B�u���@�ӬO�u�ɦ��ߡC </entry>
</row>
<row>
<entry>! $a</entry>
<entry>Not</entry>
<entry>���G�O $a ���ۤϡC</entry>
</row>
<row>
<entry>$a && $b</entry>
<entry>And</entry>
<entry>�� $a�B$b ���O�u�ɦ��ߡC</entry>
</row>
<row>
<entry>$a || $b</entry>
<entry>Or</entry>
<entry>�� $a�B$b�H�K�@�ӬO�u�ɴN���ߡC</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
"and" �M "or" ����Ӫ����A �\��O�@�˪����L���̰���ɪ��u�����Ǥ��P�C (�аѦ�
<link linkend="language.operators.precedence">�B��Ÿ�����ɪ��u������</link>)
</simpara>
</sect1>
<sect1 id="language.operators.precedence">
<title>�B��Ū����ᦸ�� (��������[����D)</title>
<para>
��Ū��u�����ǨM�w�F��ŧ@�Ϊ����F�������s�������h��C ��p���A�b 1 + 5 * 3���F�����A
���O 16 �Ӥ��O 18�A �o�O�]�� '*' ���� '+' �����u������C
</para>
<para>
�U���C�X�F�q�C�찪���u�����ǡC �̤U����ŷ|�̥��Q����C
<table>
<title>�B����u������</title>
<tgroup cols="2">
<thead>
<row>
<entry>�B����u������
</entry>
<entry>�U���B���</entry>
</row>
</thead>
<tbody>
<row>
<entry>��</entry>
<entry>,</entry>
</row>
<row>
<entry>��</entry>
<entry>or</entry>
</row>
<row>
<entry>��</entry>
<entry>xor</entry>
</row>
<row>
<entry>��</entry>
<entry>and</entry>
</row>
<row>
<entry>�k</entry>
<entry>print</entry>
</row>
<row>
<entry>��</entry>
<entry>
= += -= *= /= .= %= &= |= ^= ~= <<= >>=
</entry>
</row>
<row>
<entry>��</entry>
<entry>? :</entry>
</row>
<row>
<entry>��</entry>
<entry>||</entry>
</row>
<row>
<entry>��</entry>
<entry>&&</entry>
</row>
<row>
<entry>��</entry>
<entry>|</entry>
</row>
<row>
<entry>��</entry>
<entry>^</entry>
</row>
<row>
<entry>��</entry>
<entry>&</entry>
</row>
<row>
<entry>
�S���p non-associative</entry>
<entry>== != === !==</entry>
</row>
<row>
<entry>
�S���p non-associative</entry>
<entry>< <= > >=</entry>
</row>
<row>
<entry>��</entry>
<entry><< >></entry>
</row>
<row>
<entry>�� </entry>
<entry>+ - .</entry>
</row>
<row>
<entry>�� </entry>
<entry>* / %</entry>
</row>
<row>
<entry>�k</entry>
<entry>! ~ ++ -- (int) (double) (string) (array) (object) @</entry>
</row>
<row>
<entry>�k</entry>
<entry>[</entry>
</row>
<row>
<entry>
�S���p non-associative</entry>
<entry>new</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect1>
<sect1 id="language.operators.string">
<title>��y�B���</title>
<simpara>
����Ӥ�y�B��ťi�ΡC �Ĥ@�ӬO�걵��y�Ϊ�('.')�G
�����ȴN�O��k������y�[�쥪����y�����ڤW�h�C �ĤG�ӴN�O�걵�����X�֨�@���� ('.=')
��šC �o���X�ֺ�Ū��Ա��Ь�
<link
linkend="language.operators.assignment">�����B��� </link>�@�`�C
</simpara>
<para>
<informalexample>
<programlisting role="php">
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
</programlisting>
</informalexample>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/references.xml
+++ phpdoc/hk/language/references.xml
<chapter id="language.references">
<title>References Explained</title>
<sect1 id="language.references.whatare">
<title>What References Are</title>
<simpara>
References are a means in PHP to access the same variable content
by different names. They are not like C pointers, they are symbol
table aliases. Note that in PHP, variable name and variable content
are different, so the same content can have different names.
The most close analogy is with Unix filenames and files -
variable names are directory entries, while variable contents is
the file itself. References can be thought of as hardlinking in
Unix filesystem.
</simpara>
</sect1>
<sect1 id="language.references.whatdo">
<title>What References Do</title>
<para>
PHP references allow you to make two variables to refer to the
same content. Meaning, when you do:
<informalexample>
<programlisting role="php">
$a =& $b
</programlisting>
</informalexample>
it means that <varname>$a</varname> and <varname>$b</varname>
point to the same variable.
<note>
<para>
<varname>$a</varname> and <varname>$b</varname> are completely
equal here, that's not <varname>$a</varname> is pointing to
<varname>$b</varname> or vice versa, that's
<varname>$a</varname> and <varname>$b</varname> pointing to the
same place.
</para>
</note>
</para>
<para>
The same syntax can be used with functions, that return references,
and with <literal>new</literal> operator (in PHP 4.0.4 and later):
<informalexample>
<programlisting role="php">
$bar =& new fooclass();
$foo =& find_var ($bar);
</programlisting>
</informalexample>
</para>
<note>
<para>
Unless you use the syntax above, the result of
<literal>$bar = new fooclass()</literal> will not be the same
variable as <literal>$this</literal> in the constructor, meaning
that if you have used reference to <literal>$this</literal> in
the constructor, you should use reference assignment, or you get
two different objects.
</para>
</note>
<para>
The second thing references do is to pass variables
by-reference. This is done by making a local variable in a function and
a variable in the calling scope reference to the same content. Example:
<informalexample>
<programlisting role="php">
function foo (&$var) {
$var++;
}
$a=5;
foo ($a);
</programlisting>
</informalexample>
will make <varname>$a</varname> to be 6. This happens because in
the function <varname>foo</varname> the variable
<varname>$var</varname> refers to the same content as
<varname>$a</varname>. See also more detailed explanations about <link
linkend="language.references.pass">passing by reference</link>.
</para>
<simpara>
The third thing reference can do is <link
linkend="language.references.return">return by reference</link>.
</simpara>
</sect1>
<sect1 id="language.references.arent">
<title>What References Are Not</title>
<para>
As said before, references aren't pointers. That means, the
following construct won't do what you expect:
<informalexample>
<programlisting role="php">
function foo (&$var) {
$var =& $GLOBALS["baz"];
}
foo($bar);
</programlisting>
</informalexample>
</para>
<simpara>
What happens is that <varname>$var</varname> in foo will be bound
with <varname>$bar</varname> in caller, but then it will be
re-bound with <varname>$GLOBALS["baz"]</varname>. There's no way
to bind <varname>$bar</varname> in the calling scope to something else
using the reference mechanism, since <varname>$bar</varname> is not
available in the function foo (it is represented by
<varname>$var</varname>, but <varname>$var</varname> has only
variable contents and not name-to-value binding in the calling
symbol table).
</simpara>
</sect1>
<sect1 id="language.references.pass">
<title>Passing by Reference</title>
<para>
You can pass variable to function by reference, so that function could modify
its arguments. The sytax is as follows:
<informalexample>
<programlisting role="php">
function foo (&$var) {
$var++;
}
$a=5;
foo ($a);
// $a is 6 here
</programlisting>
</informalexample>
Note that there's no reference sign on function call - only on
function definition. Function definition alone is enough to
correctly pass the argument by reference.
</para>
<para>
Following things can be passed by reference:
<itemizedlist>
<listitem>
<simpara>
Variable, i.e. <literal>foo($a)</literal>
</simpara>
</listitem>
<listitem>
<simpara>
New statement, i.e. <literal>foo(new foobar())</literal>
</simpara>
</listitem>
<listitem>
<para>
Reference, returned from a function, i.e.:
<informalexample>
<programlisting role="php">
function &bar()
{
$a = 5;
return $a;
}
foo(bar());
</programlisting>
</informalexample>
See also explanations about <link
linkend="language.references.return">returning by reference</link>.
</para>
</listitem>
</itemizedlist>
</para>
<para>
Any other expression should not be passed by reference, as the
result is undefined. For example, the following examples of passing
by reference are invalid:
<informalexample>
<programlisting role="php">
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar));
foo($a = 5) // Expression, not variable
foo(5) // Constant, not variable
</programlisting>
</informalexample>
These requirements are for PHP 4.0.4 and later.
</para>
</sect1>
<sect1 id="language.references.return">
<title>Returning References</title>
<para>
Returning by-reference is useful when you want to use a function
to find which variable a reference should be bound to. When
returning references, use this syntax:
<informalexample>
<programlisting role="php">
function &find_var ($param) {
...code...
return $found_var;
}
$foo =& find_var ($bar);
$foo->x = 2;
</programlisting>
</informalexample>
In this example, the property of the object returned by the
<varname>find_var</varname> function would be set, not the
copy, as it would be without using reference syntax.
</para>
<note>
<simpara>
Unlike parameter passing, here you have to use
<literal>&</literal> in both places - to indicate that you
return by-reference, not a copy as usual, and to indicate that
reference binding, rather than usual assignment, should be done
for <varname>$foo</varname>.
</simpara>
</note>
</sect1>
<sect1 id="language.references.unset">
<title>Unsetting References</title>
<para>
When you unset the reference, you just break the binding between
variable name and variable content. This does not mean that
variable content will be destroyed. For example:
<informalexample>
<programlisting role="php">
$a = 1;
$b =& $a;
unset ($a);
</programlisting>
</informalexample>
won't unset <varname>$b</varname>, just <varname>$a</varname>.
</para>
<simpara>
Again, it might be useful to think about this as analogous to Unix
<command>unlink</command> call.
</simpara>
</sect1>
<sect1 id="language.references.spot">
<title>Spotting References</title>
<simpara>
Many syntax constructs in PHP are implemented via referencing
mechanisms, so everything told above about reference binding also
apply to these constructs. Some constructs, like passing and
returning by-reference, are mentioned above. Other constructs that
use references are:
</simpara>
<sect2 id="references.global">
<title><literal>global</literal> References</title>
<para>
When you declare variable as <command>global $var</command> you
are in fact creating reference to a global variable. That means,
this is the same as:
<informalexample>
<programlisting role="php">
$var =& $GLOBALS["var"];
</programlisting>
</informalexample>
</para>
<simpara>
That means, for example, that unsetting <varname>$var</varname>
won't unset global variable.
</simpara>
</sect2>
<sect2 id="references.this">
<title><literal>$this</literal></title>
<simpara>
In an object method, <varname>$this</varname> is always reference
to the caller object.
</simpara>
</sect2>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/types.xml
+++ phpdoc/hk/language/types.xml
<chapter id="language.types">
<title>�U���ܼ�</title>
<para>
PHP �i�H�B�z�H�U�ƾڧκA:
<itemizedlist>
<listitem>
<simpara>
<link linkend="language.types.array">�}�C </link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.double">�B�I��
</link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.integer">��� </link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.object">���O </link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.string">��y </link>
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
�{�����q�`���Ϋ��w�ܼƬO����κA�C PHP
�|�b�B��ھڸ��ܼƩҧt���ȨӦۦ�M�w�ӫ��������������ܼơC
</simpara>
<simpara>
�p�G�A�Q�ۤv�M�w�ܼƪ��κA�Χ����ܼƪ��κA�A �n��N�O��<link
linkend="language.types.typecasting">�ܼƮM��</link>�A ���M�N�O�ե�
<function>settype</function>��ơC
</simpara>
<simpara>
�����`�N���P�κA���ܼƦb�S�w���p�U�����P���{�C �o�b <link
linkend="language.types.type-juggling">Type Juggling</link>�@�`������ԲӪ��y�z�C
</simpara>
<sect1 id="language.types.integer">
<title>���</title>
<para>
���
<informalexample>
<programlisting role="php">
$a = 1234; # decimal number
$a = -123; # a negative number
$a = 0123; # octal number (equivalent to 83 decimal)
$a = 0x12; # hexadecimal number (equivalent to 18 decimal)
</programlisting>
</informalexample>
The size of an integer is platform-dependent, although a
maximum value of about 2 billion is the usual value
(that's 32 bits signed).
</para>
</sect1>
<sect1 id="language.types.double">
<title>�B�I��</title>
<para>
���w�B�I�κA (DOUBLES) ���ܼƥi�ΥH�U�y�k : <informalexample>
<programlisting role="php">
$a = 1.234; $a = 1.2e3;
</programlisting>
</informalexample>
The size of a floating point number is platform-dependent,
although a maximum of ~1.8e308 with a precision of roughly 14
decimal digits is a common value (that's 64 bit IEEE format).
</para>
<warning id="warn.float-precision">
<para>
It is quite usual that simple decimal fractions like
<literal>0.1</literal> or <literal>0.7</literal> cannot be
converted into their internal binary counterparts without a
little loss of precision. This can lead to confusing results: for
example, <literal>floor((0.1+0.7)*10)</literal> will usually
return <literal>7</literal> instead of the expected
<literal>8</literal> as the result of the internal representation
really being something like <literal>7.9999999999...</literal>.
</para>
<para>
This is related to the fact that it is impossible to exactly
express some fractions in decimal notation with a finite number
of digits. For instance, <literal>1/3</literal> in decimal form
becomes <literal>0.3333333. . .</literal>.
</para>
<para>
So never trust floating number results to the last digit and
never compare floating point numbers for equality. If you really
need higher precision, you should use the <link
linkend="ref.bc">arbitrary precision math functions</link>
or <link linkend="ref.gmp">gmp</link> functions instead.
</para>
</warning>
</sect1>
<sect1 id="language.types.string">
<title>��y
</title>
<para>
���w�ܼƬ���y�κA���X�ػy�k�i�H�ΡC </para>
<para>
If the string is enclosed in double-quotes ("), variables within
�p�G��y�O�������]�_�Ӫ��ܡA �t�b�䤤���ܼƷ|�Q�i�} (���M�]�����R�����R�ɪ�����)�C
�M C�B PERL �@�ˡA �Q�[�J�S�O������ťi�H�e�m "\"�Ÿ�:
<table>
<title>�S�O����Ÿ���</title>
<tgroup cols="2">
<thead>
<row>
<entry>�Ÿ���</entry>
<entry>�t�N</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>\n</literal></entry>
<entry>�}�s�@�� (LF or 0x0A in ASCII)</entry>
</row>
<row>
<entry><literal>\r</literal></entry>
<entry> �_�� (CR or 0x0D in ASCII)</entry>
</row>
<row>
<entry><literal>\t</literal></entry>
<entry>���� (HT or 0x09 in ASCII)</entry>
</row>
<row>
<entry><literal>\\</literal></entry>
<entry>backslash �ϱu</entry>
</row>
<row>
<entry><literal>\$</literal></entry>
<entry>$ �Ÿ�</entry>
</row>
<row>
<entry><literal>\"</literal></entry>
<entry>����</entry>
</row>
<row>
<entry><literal>\[0-7]{1,3}</literal></entry>
<entry>
8 �i��r�� (�������O REGULAR EXPRESSION �����F��k�E)
</entry>
</row>
<row>
<entry><literal>\x[0-9A-Fa-f]{1,2}</literal></entry>
<entry>
16 �i��r��
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
�A�i�H�b "\" ���W����O���r���A ���O�b�{������ɷ|��ĵ�i�C(���D�t�~�ճ]�A
�_�hĵ�i���|�v�T�{������C
</para>
<para>
�ĤG�ةw�q��y����k����k�O�γ�� "'"�C �b�����y���u����ӫ���G "\\" �M
"\'"�A �o�O���F��b��y���[�J����C �����y�����ܼƨä��| �Q�i�}�C
</para>
<simpara>
�t�~�٦��@�جɩw��y����k�G �� HERE DOC ���y��
("<<<")�C �`�N�n�b
<literal><<<</literal>����[�W�@�ӿ��Ѧr�å����b��y���᪺�Ĥ@�� �̶}�Y
�[�W�P�@�ӿ��Ѧr�C
</simpara>
<simpara>
The closing identifier <emphasis>must</emphasis> begin in the
first column of the line. Also, the identifier used must follow
the same naming rules as any other label in PHP: it must contain
only alphanumeric characters and underscores, and must start with
a non-digit character or underscore.
</simpara>
<para>
Here doc text behaves just like a double-quoted string, without
the double-quotes. This means that you do not need to escape quotes
in your here docs, but you can still use the escape codes listed
above. Variables are expanded, but the same care must be taken
when expressing complex variables inside a here doc as with
strings.
<example>
<title>�� Here doc �ɩw��y���ܽd</title>
<programlisting>
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
/* More complex example, with variables. */
class foo {
var $foo;
var $bar;
function foo() {
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}
$foo = new foo();
$name = 'MyName';
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
</programlisting>
</example>
</para>
<note>
<para>
�b PHP �� 4 ���~��� Here doc �y�k. </para>
</note>
<para>
��y�i�H���I '.' �걵�_�ӡC�`�N�� "+" ����s��y�O�L�Ī��C
<link linkend="language.operators.string">��y�B��� </link> �@�`������ԲӪ������C
</para>
<para>
�b��y�����C�@�Ӧr���i�H���O�r���}�C�����@�ӭӤ����A �p���i�H�ι� C ���˪��y�k�ӽեΡA
�ЬݤU�� �G
</para>
<para>
<example>
<title>�ܽd��y </title>
<programlisting role="php">
<?php
/* Assigning a string. */
$str = "This is a string";
/* Appending to it. */
$str = $str . " with some more text";
/* Another way to append, includes an escaped newline. */
$str .= " and a newline at the end.\n";
/* This string will end up being '<p>Number: 9</p>' */
$num = 9;
$str = "<p>Number: $num</p>";
/* This one will be '<p>Number: $num</p>' */
$num = 9;
$str = '<p>Number: $num</p>';
/* Get the first character of a string */
$str = 'This is a test.';
$first = $str[0];
/* Get the last character of a string. */
$str = 'This is still a test.';
$last = $str[strlen($str)-1];
?>
</programlisting>
</example>
</para>
<sect2 id="language.types.string.conversion">
<title>��y�ܴ� </title>
<simpara>
����y�Q�����O�Ʀr���˨Ӿާ@�ɡA ��κA�M�ȸ�q�H�U���W�h�G </simpara>
<simpara>
�p�G��y���� '.'�B 'e'�B 'E'�Ÿ��A �h��y�|�ܦ��B�I�Ʀr�A �Ϥ��h�|�Q�����O��ơC
</simpara>
<para>
��y�ҥN���ƭȵ���y�}�Y���r���өw�A �u�n��y�}�Y�����O�X�z���Ʀr�Ÿ��h��y���ȴN�|�O
0�C �X�z���Ʀr�Ÿ��]�A���t���B �᭱�� 0 �� 9 �����ԧB�Ʀr�B �p���I�B
�̫�O�i���i�L�����ƥN���Ÿ� ("E" �� "e" �᭱��W�@����ԧB�Ʀr)�C
</para>
<simpara>
�p�G�b���F�ܤ��Y�@���O��y�h�B��G�n�ݲĤG���O�����ܼƧκA�C </simpara>
<informalexample>
<programlisting role="php">
$foo = 1 + "10.5"; // $foo is double (11.5)
$foo = 1 + "-1.3e3"; // $foo is double (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is integer (1)
$foo = 1 + "bob3"; // $foo is integer (1)
$foo = 1 + "10 Small Pigs"; // $foo is integer (11)
$foo = 1 + "10 Little Piggies"; // $foo is integer (11)
$foo = "10.0 pigs " + 1; // $foo is integer (11)
$foo = "10.0 pigs " + 1.0; // $foo is double (11)
</programlisting>
</informalexample>
<simpara>
�b Unix ��U strtod(3) �@������������o���ܴ�����ơC
</simpara>
<para>
�p�G�n�եΥ��`���ܽd���Ҥl�A �i�H��{���X�ƻs��@�ӷs���{���q���ô��J�U�C���O��A
���i�D�A�ϥΤ����ܼƬO����κA :
<informalexample>
<programlisting role="php">
echo "\$foo==$foo; type is " . gettype ($foo) . "<br>\n";
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
<sect1 id="language.types.array">
<title>�}�C</title>
<para>
PHP ���}�C�P�ɾ֦������� HASH TABLE �M ���ު� INDEX TABLE ���S�ʡC(���p�r���ަ��}�C
ASSOCIATIVE ARRAY �M �ڶq VECTOR �N�O��ӨҤl)
</para>
<sect2 id="language.types.array.single-dim">
<title>����}�C</title>
<para>
�b PHP �� �ƭȯ��ަ��M���p�r���ަ��o�����}�C���W�O�@�˪��C �A�i��
<function>list</function> �� <function>array</function>
��ƨӫإ߰}�C�A �]�i�H�������w�}�C���������ȡC
<informalexample>
<programlisting role="php">
$a[0] = "abc";
$a[1] = "def";
$b["foo"] = 13;
</programlisting>
</informalexample>
</para>
<para>
���p�S�����X�}�C�������ѷӼи��A PHP �|�b�}�C�̥��ݥ[�J�@�Ӥ����A
�ç�ƭȦs��Ӥ������h�C �γo�ӯS�I�A�i�H��²��a�إߤ@�Ӱ}�C�C
<informalexample>
<programlisting role="php">
$a[] = "hello"; // $a[2] == "hello"
$a[] = "world"; // $a[3] == "world"
</programlisting>
</informalexample>
</para>
<para>
�n��}�C���������ƧǡA �i���}�C���κA�ե� <function>asort</function>,
<function>arsort</function>, <function>ksort</function>,
<function>rsort</function>, <function>sort</function>,
<function>uasort</function>, <function>usort</function>,
<function>uksort</function> ����ơC </para>
<para>
<function>count</function> ��Ʒ|���X�}�C�����h�֭Ӥ����C
</para>
<para>
�A�i�H�� <function>next</function>��
<function>prev</function>��ƨӫ��V�}�C�������P�����A �t�@�ӱ`�Ϊ��P����ƬO
<function>each</function>.
</para>
</sect2>
<sect2 id="language.types.array.multi-dim">
<title>�����}�C</title>
<para>
�����}�C(�h���}�C) ���ϥΨ��O��²�檺�C �A�u�n�b�}�C�᭱�[�h�@�Ӥ� "[ ]"�A
�}�C�K�h�F�@�Ӻ��ơG
<informalexample>
<programlisting role="php">
$a[1] = $f; # one dimensional examples
$a["foo"] = $f;
$a[1][0] = $f; # two dimensional
$a["foo"][2] = $f; # (you can mix numeric and associative indices)
$a[3]["bar"] = $f; # (you can mix numeric and associative indices)
$a["foo"][4]["bar"][0] = $f; # four dimensional!
</programlisting>
</informalexample>
</para>
<para>
PHP3 �ä����\�����b��y�����ѷӦh���}�C���������C �p�U�Ҫ��{���N���Ϳ��~�����G�C
<informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This won't work: $a[3][bar]";
</programlisting>
</informalexample>
�� PHP3�A �H�W�B�⪺���G�N�O This won't work: Array[bar]�I ��I�o�Ӱ��D�n�Ψ� "."
��y���X�B��Ť~��G <informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This will work: " . $a[3][bar];
</programlisting>
</informalexample>
</para>
<para>
�b PHP4 �������A �Ϊ�A���b��y����}�C�ѷӥ]�_�ӴN�ѨM�F�H�W���j�ǰ��D :
<informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This will work: {$a[3][bar]}";
</programlisting>
</informalexample>
</para>
<para>
�n�@�Ӧh�����}�C���ܦh��k�C ��������������O��
<function>array</function> ��ƨӫ��w���p�r���ަ��}�C ASSOCIATIVE ARRAY �����ȡC
�H�U��q�{���X���\��O�����@�˪� :
<informalexample>
<programlisting role="php">
# Example 1:
$a["color"] = "red";
$a["taste"] = "sweet";
$a["shape"] = "round";
$a["name"] = "apple";
$a[3] = 4;
# Example 2:
$a = array(
"color" => "red",
"taste" => "sweet",
"shape" => "round",
"name" => "apple",
3 => 4
);
</programlisting>
</informalexample>
</para>
<para>
�α_���� <function>array</function> ��ƥi�H�إߥX�h�����}�C :
<informalexample>
<programlisting role="php">
<?php
$a = array(
"apple" => array(
"color" => "red",
"taste" => "sweet",
"shape" => "round"
),
"orange" => array(
"color" => "orange",
"taste" => "tart",
"shape" => "round"
),
"banana" => array(
"color" => "yellow",
"taste" => "paste-y",
"shape" => "banana-shaped"
)
);
echo $a["apple"]["taste"]; # will output "sweet"
?>
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
<sect1 id="language.types.object">
<title>����</title>
<sect2 id="language.types.object.init">
<title>�إߪ���</title>
<para>
�� NEW ���O�i�H���ܼƫ��w���Y�@����C
<informalexample>
<programlisting role="php">
<?php
class foo {
function do_foo() {
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
</programlisting>
</informalexample>
</para>
<simpara>
For a full discussion, please read the section <link
linkend="language.oop">Classes and Objects</link>.
</simpara>
</sect2>
</sect1>
<sect1 id="language.types.type-juggling">
<title>�U���ܼƶ�������</title>
<simpara>
PHP �J���ݭn�]���䴩���T�a���i�ܼƪ��κA�C �ܼƪ����ε������x�s����Ʀөw�G
�p�G�A���y�s�� var�����A var �|�O��y���ܼơF �p�G�s�J���O��� var�A���N�ܦ���ƧΡC
</simpara>
<para>
�U���� "+" �[�����B��ӥܽd PHP ��˦۰ʽվ��ܼƪ��κA�C
�p�G�[�ƩM�Q�[�Ƥ�����@�ӬO�B�I�ơA �B�⪺���G�N�|�O�B�I�ơA �Ϥ��h���G�|�O��ƧκA�C
�`�N�o�ؽվ�u�O�Φb�B�⤧���A �ä��|���ܥ[�ƩM�Q�[�ƥ��Ӫ����ΡC
<informalexample>
<programlisting role="php">
$foo = "0"; // $foo is string (ASCII 48)
$foo++; // $foo is the string "1" (ASCII 49)
$foo += 1; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a double (3.3)
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
$foo = 5 + "10 Small Pigs"; // $foo is integer (15)
</programlisting>
</informalexample>
</para>
<simpara>
�Y���W�����Ҥl�Ϊ��y�k����¡A �i�H�Ѧ� <link
linkend="language.types.string.conversion">��y�ܴ�</link>�@�`�C
</simpara>
<simpara>
�p�G���Q PHP �۰ʽո`�ܼƪ��κA�ӥ���ۤv���w�ܼƦb�B�⤤���κA�i��
<link linkend="language.types.typecasting">�κA�M��</link>. �C �p�Q�����ܼƪ����ΡA
�i�ϥ�
<function>settype</function>��ơC
</simpara>
<para>
���p�A�Q�ե��`�����ܨҡA �i�H��{���X�����ƨ�X�ӵM��[�W�U���@����O�A
�A�i�D���ܼƪ��W�r�A ���i�D�A�ܼƪ��κA:
<informalexample>
<programlisting role="php">
echo "\$foo==$foo; type is " . gettype ($foo) . "<br>\n";
</programlisting>
</informalexample>
</para>
<note>
<para>
PHP �Ȯ��٨S���w�q���@�ӫD�}�C�ܼƦ۰��ഫ���}�C�ܼơC
<informalexample>
<programlisting role="php">
$a = 1; // $a is an integer
$a[0] = "f"; // $a becomes an array, with $a[0] holding "f"
</programlisting>
</informalexample>
</para>
<para>
�W�����Ҥl�ݰ_�Ӧ�o�q�G "f" �|�ܦ��O�}�C $a ���ĭӤ����A �{�b�ݬݤU�ӥܨҡG
<informalexample>
<programlisting role="php">
$a = "1"; // $a is a string
$a[0] = "f"; // What about string offsets? What happens?
</programlisting>
</informalexample>
</para>
<para>
�ѩ� PHP �ΨӪ��ܤ�y���Y�Ӧr�����y�k�M�ΨӪ��ܰ}�C���Y�Ӥ������y�k�O�@�˪��A
�W�����ҥy�|���ͪ[�q�G "f" ���ӥN����y�ܼ� $a �������Ӧr���٬O���ӥN���}�C�ܼ� $a[]
�����Ĥ@�Ӥ����H
</para>
<para>
�]���b PHP 3.0.12 and PHP 4.0b3-RC4 ��Ӫ������A �èS���w�q�W�z���ܴ��ӫ�˰��C
�ѨM����k�ثe�٦b�Q�����C
</para>
</note>
<sect2 id="language.types.typecasting">
<title>�κA�M��
</title>
<para>
�M C ���y�k�@�ˡA �n���ܼƪ��κA�M�����t�@�اκA�i�H�ζ�A�� "( )"
��Q���w�����άA�_�ө�b�ܼƫe���C
<informalexample>
<programlisting role="php">
$foo = 10; // $foo is an integer
$bar = (double) $foo; // $bar is a double
</programlisting>
</informalexample>
</para>
<para>
�U�C���M���O�X�k���G
<itemizedlist>
<listitem>
<simpara>(int), (integer) - �������</simpara>
</listitem>
<listitem>
<simpara>(real), (double), (float) - �����B�I��</simpara>
</listitem>
<listitem>
<simpara>(string) - ������y</simpara>
</listitem>
<listitem>
<simpara>(array) - �����}�C</simpara>
</listitem>
<listitem>
<simpara>(object) - ��������</simpara>
</listitem>
</itemizedlist>
</para>
<para>
�ѩ�A�����i�H��i�Ů�M����Ÿ��A �ҥH�U�������O�O���Ī�:
<informalexample>
<programlisting role="php">
$foo = (int) $bar;
$foo = ( int ) $bar;
</programlisting>
</informalexample>
</para>
<para>
�Y�ǮM�������G�ä���@���ݥX�ӡA �i��o�˪��ഫ�ɭn�d�N�H�U�X�I�C
</para>
<para>
����Ʀr�Τ�y�M�����}�C�ɡA �ƭȩξ�y��y�|�����}�C�������Ӥ����C
<informalexample>
<programlisting role="php">
$var = 'ciao';
$arr = (array) $var;
echo $arr[0]; // outputs 'ciao'
</programlisting>
</informalexample>
</para>
<para>
����Ʀr�Τ�y�M��������ɡA ���|�۰ʲ��ͤ@�ӥs SCALAR ���ݩʡA
�����x�s�F�M���e�ܼƤ������e�C
<informalexample>
<programlisting role="php">
$var = 'ciao';
$obj = (object) $var;
echo $obj->scalar; // outputs 'ciao'
</programlisting>
</informalexample>
</para>
</sect2>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/hk/language/variables.xml
+++ phpdoc/hk/language/variables.xml
<?xml encoding="iso-8859-1"?>
<chapter id="language.variables">
<title>�U���ܼ�</title>
<sect1 id="language.variables.basics">
<title>����</title>
<simpara>
�Ҧ� PHP ���ܼƫe�������@�� "$" �Ÿ��A �᭱����ܼƪ��W�r�C �`�N�ܼƦW�٬O���j�p�g���C
</simpara>
<para>
Variable names follow the same rules as other labels in PHP. A
valid variable name starts with a letter or underscore, followed
by any number of letters, numbers, or underscores. As a regular
expression, it would be expressed thus:
'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
</para>
<note>
<simpara>
For our purposes here, a letter is a-z, A-Z, and the ASCII
characters from 127 through 255 (0x7f-0xff).
</simpara>
</note>
<para>
<informalexample>
<programlisting role="php">
$var = "Bob";
$Var = "Joe";
echo "$var, $Var"; // outputs "Bob, Joe"
$4site = 'not yet'; // invalid; starts with a number
$_4site = 'not yet'; // valid; starts with an underscore
$t�yte = 'mansikka'; // valid; '?' is ASCII 228.
</programlisting>
</informalexample>
</para>
<para>
�b PHP3 ���ɴ��A ���w���ܼƪ����O�ȡA �Ҧp��@����F�����w���ܼƪ��ܡA
�ܼƩ��x�s���N�O���F���p��X�Ӫ��ȡC �����ޥӷN�q�O�p�G�A��Y�ܼƫ��w���t�@���ܼƫ�A
���ܨ䤤�@�Ӫ����e�ä��|�v�T�t�~���@�ӡC �Q�i�@�B�A�ѳo�ث��w�ܼƤ�k�A �Ь�
<link
linkend="language.expressions">���F��</link>�@�`�C
</para>
<para>
PHP4 �h���ѤF�t�@�ث��w�ܼƪ���k:
<emphasis>�ܼưѷ�</emphasis>. �N��O�s�ܼƥu�O�ѷӥ��Ӫ��ܼƤ����ȡC (���ӻ��k�A
�s���ܼƥu�O���Ӫ��ܼƪ�"�O�W"�A �]�i���s�ܼƬO���ܼƪ�"����") �L�ק��ܭ��@���ܼơA
��ʳ��P�ɤϬM�b�t�@���ܼƤ��C �ѩ����ܼƪ��ȨèS���Q�ۨ�s�ܼƤ��A
�ҥH�o�ث��w�ܼƪ���k����ɷ|�֤@�I�A ���]�u�O�@�I�Ӥw�C
�u���b���w�j�����}�C�B����άO�b�j�q���j��ާ@���~�|�ݥX�įq�ӡC
</para>
<para>
�@�ѷӫ��w���覡�O�b�Q�ѷӪ��ܼ�(���ܼ�)�e�[�W��(&) �Ÿ��C
���U�����ܨҷ|�s�X��y�ۦP���y�l:
<informalexample>
<programlisting role="php">
<?php
$foo = 'Bob'; // Assign the value 'Bob' to $foo
$bar = &$foo; // Reference $foo via $bar.
$bar = "My name is $bar"; // Alter $bar...
echo $foo; // $foo is altered too.
echo $bar;
?>
</programlisting>
</informalexample>
</para>
<para>
���@�I�ܭ��n���O�u���u�����ܼƤ~�i�H�@�����ܼƳQ�ѷӡC
<informalexample>
<programlisting role="php">
<?php
$foo = 25;
$bar = &$foo; // This is a valid assignment.
$bar = &(24 * 7); // Invalid; references an unnamed expression.
function test() {
return 25;
}
$bar = &test(); // Invalid.
?>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="language.variables.predefined">
<title>�w�w�]�n���ܼ�</title>
<simpara>
PHP provides a large number of predefined variables to any script
which it runs. Many of these variables, however, cannot be fully
documented as they are dependent upon which server is running, the
version and setup of the server, and other factors. Some of these
variables will not be available when PHP is run on the
command-line.
</simpara>
<simpara>
Despite these factors, here is a list of predefined variables
available under a stock installation of PHP 3 running as a module
under a stock installation of <ulink
url="&url.apache;">Apache</ulink> 1.3.6.
</simpara>
<simpara>
For a list of all predefined variables (and lots of other useful
information), please see (and use) <function>phpinfo</function>.
</simpara>
<note>
<simpara>
This list is neither exhaustive nor intended to be. It is simply
a guideline as to what sorts of predefined variables you can
expect to have access to in your script.
</simpara>
</note>
<sect2 id="language.variables.predefined.apache">
<title>Apache variables</title>
<simpara>
These variables are created by the <ulink
url="&url.apache;">Apache</ulink> webserver. If you are running
another webserver, there is no guarantee that it will provide the
same variables; it may omit some, or provide others not listed
here. That said, a large number of these variables are accounted
for in the <ulink url="&url.cgispec;">CGI 1.1
specification</ulink>, so you should be able to expect those.
</simpara>
<simpara>
Note that few, if any, of these will be available (or indeed have
any meaning) if running PHP on the command line.
</simpara>
<para>
<variablelist>
<varlistentry>
<term>GATEWAY_INTERFACE</term>
<listitem>
<simpara>
What revision of the CGI specification the server is using;
i.e. 'CGI/1.1'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_NAME</term>
<listitem>
<simpara>
The name of the server host under which the current script is
executing. If the script is running on a virtual host, this
will be the value defined for that virtual host.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_SOFTWARE</term>
<listitem>
<simpara>
Server identification string, given in the headers when
responding to requests.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_PROTOCOL</term>
<listitem>
<simpara>
Name and revision of the information protocol via which the
page was requested; i.e. 'HTTP/1.0';
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REQUEST_METHOD</term>
<listitem>
<simpara>
Which request method was used to access the page; i.e. 'GET',
'HEAD', 'POST', 'PUT'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>QUERY_STRING</term>
<listitem>
<simpara>
The query string, if any, via which the page was accessed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>DOCUMENT_ROOT</term>
<listitem>
<simpara>
The document root directory under which the current script is
executing, as defined in the server's configuration file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT</term>
<listitem>
<simpara>
Contents of the <literal>Accept:</literal> header from the
current request, if there is one.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT_CHARSET</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Charset:</literal> header
from the current request, if there is one. Example:
'iso-8859-1,*,utf-8'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT_ENCODING</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Encoding:</literal> header
from the current request, if there is one. Example: 'gzip'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT_LANGUAGE</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Language:</literal> header
from the current request, if there is one. Example: 'en'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_CONNECTION</term>
<listitem>
<simpara>
Contents of the <literal>Connection:</literal> header from
the current request, if there is one. Example: 'Keep-Alive'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_HOST</term>
<listitem>
<simpara>
Contents of the <literal>Host:</literal> header from the
current request, if there is one.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_REFERER</term>
<listitem>
<simpara>
The address of the page (if any) which referred the browser
to the current page. This is set by the user's browser; not
all browsers will set this.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_USER_AGENT</term>
<listitem>
<simpara>
Contents of the <literal>User_Agent:</literal> header from
the current request, if there is one. This is a string
denoting the browser software being used to view the current
page; i.e. <computeroutput>Mozilla/4.5 [en] (X11; U; Linux
2.2.9 i586)</computeroutput>. Among other things, you can use
this value with <function>get_browser</function> to tailor
your page's functionality to the capabilities of the user's
browser.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REMOTE_ADDR</term>
<listitem>
<simpara>
The IP address from which the user is viewing the current
page.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REMOTE_PORT</term>
<listitem>
<simpara>
The port being used on the user's machine to communicate with
the web server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SCRIPT_FILENAME</term>
<listitem>
<simpara>
The absolute pathname of the currently executing script.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_ADMIN</term>
<listitem>
<simpara>
The value given to the SERVER_ADMIN (for Apache) directive in
the web server configuration file. If the script is running
on a virtual host, this will be the value defined for that
virtual host.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_PORT</term>
<listitem>
<simpara>
The port on the server machine being used by the web server
for communication. For default setups, this will be '80';
using SSL, for instance, will change this to whatever your
defined secure HTTP port is.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_SIGNATURE</term>
<listitem>
<simpara>
String containing the server version and virtual host name
which are added to server-generated pages, if enabled.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PATH_TRANSLATED</term>
<listitem>
<simpara>
Filesystem- (not document root-) based path to the current
script, after the server has done any virtual-to-real
mapping.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SCRIPT_NAME</term>
<listitem>
<simpara>
Contains the current script's path. This is useful for pages
which need to point to themselves.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REQUEST_URI</term>
<listitem>
<simpara>
The URI which was given in order to access this page; for
instance, '/index.html'.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
<sect2 id="language.variables.predefined.environment">
<title>Environment variables</title>
<simpara>
These variables are imported into PHP's global namespace from the
environment under which the PHP parser is running. Many are
provided by the shell under which PHP is running and different
systems are likely running different kinds of shells, a
definitive list is impossible. Please see your shell's
documentation for a list of defined environment variables.
</simpara>
<simpara>
Other environment variables include the CGI variables, placed
there regardless of whether PHP is running as a server module or
CGI processor.
</simpara>
</sect2>
<sect2 id="language.variables.predefined.php">
<title>PHP variables</title>
<simpara>
These variables are created by PHP itself. The
<varname>$HTTP_*_VARS</varname> variables are available only if
the <link linkend="ini.track-vars">track_vars</link>
configuration is turned on. When enabled, the variables are
always set, even if they are empty arrays. This prevents
a malicious user from spoofing these variables.
</simpara>
<note>
<para>
As of PHP 4.0.3, <link
linkend="ini.track-vars">track_vars</link> is always turned on,
regardless of the configuration file setting.
</para>
</note>
<para>
If the <link
linkend="ini.register-globals">register_globals</link> directive
is set, then these variables will also be made available in the
global scope of the script; i.e., separate from the
<varname>$HTTP_*_VARS</varname> arrays. This feature should be
used with care, and turned off if possible; while the
<varname>$HTTP_*_VARS</varname> variables are safe, the bare
global equivalents can be overwritten by user input, with
possibly malicious intent. If you cannot turn off <link
linkend="ini.register-globals">register_globals</link>, you must
take whatever steps are necessary to ensure that the data you are
using is safe.
</para>
<para>
<variablelist>
<varlistentry>
<term>argv</term>
<listitem>
<simpara>
Array of arguments passed to the script. When the script is
run on the command line, this gives C-style access to the
command line parameters. When called via the GET method, this
will contain the query string.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>argc</term>
<listitem>
<simpara>
Contains the number of command line parameters passed to the
script (if run on the command line).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_SELF</term>
<listitem>
<simpara>
The filename of the currently executing script, relative to
the document root. If PHP is running as a command-line
processor, this variable is not available.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_COOKIE_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via HTTP cookies.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_GET_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the HTTP GET method.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_POST_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the HTTP POST method.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_POST_FILES</term>
<listitem>
<simpara>
An associative array of variables containing information
about files uploaded via the HTTP POST method. See <link
linkend="features.file-upload.post-method">POST method
uploads</link> for information on the contents of
<varname>$HTTP_POST_FILES</varname>.
</simpara>
<para>
<varname>$HTTP_POST_FILES</varname> is available only in PHP
4.0.0 and later.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ENV_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the parent environment.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_SERVER_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script from the HTTP server. These variables are analogous to
the Apache variables described above.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
</sect1>
<sect1 id="language.variables.scope">
<title>�ܼƪ����Ľd��</title>
<simpara>
�ܼƪ����Ľd��O���u���b�ӽd���q���~���D���o�ˤ@���ܼƦs�b�åi�s������x���ȡC
�j�e�D�O�Ҧ��� PHP �ܼƳ��u����@�����Ľd��C �o���Ľd����i��Q include() �M
require() ����C �Ьݥܽd:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1;
include "b.inc";
</programlisting>
</informalexample>
<simpara>
�b b.inc ��� $a �ܼƪ��Ȥ]�O 1 �C �M�ӡA
�b��Ƥ����ܼƨ䦳�Ľd��h�����b��ƪ����餧���C
���i��Ʈɹq�����|���D�b��ƳQ�եΤ��e�������ܼƴ��Q�w�q�A
�өҦ��b��ư���ɤ~�w�q���ܼƦb���X��ƫ᳣�|�����C �p�U��:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1; /* global scope */
Function Test () {
echo $a; /* reference to local scope variable */
}
Test ();
</programlisting>
</informalexample>
<simpara>
�ӵ{���ä��|���X����Ȧ]���b echo $a �o�@���O���A $a
�����Ľd��u�O�b��Ƥ����A���b��Ʒ����èS���w�q $a ���ȡF �t�@�譱�b��ƥ~�� $a
�����Ľd��ä��|���i�����إh�C �p�A�O C �{�������ܽЯd�N�o�ئ��Ľd�w�k�M C
���@�ˡG �b C �����Ҧ��D�{�������ܼƳ��O�����ܼơC (���D�b��Ƥ��t�~���w�C) �]�� C
���覡�|���p�ߦb��Ƥ���ʤF�~���ܼơA �ҥH�b PHP
�������p�Q�s���~���ܼƪ��ܴN�����ŧi�@�ӥ����ܼơC �ܽd�p�U:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1;
$b = 2;
Function Sum () {
global $a, $b;
$b = $a + $b;
}
Sum ();
echo $b;
</programlisting>
</informalexample>
<simpara>
�W�����Ҥl�~�|�L�X "3"�C �b��Ƥ��ŧi $a�B$b
�������ܼƤ���N�i�H�s���b��ƥ~�����ܼơC �@�Ө�ƥi�H�ŧi���N�h�ӥ����ܼơC
</simpara>
<simpara>
�t�~�@�Ӧs���~���ܼƪ���k�O�ե� PHP ���m�� $GLOBALS[] �}�C�C
�{�b��e�����Ҥl��g�@�U: </simpara>
<informalexample>
<programlisting role="php">
$a = 1;
$b = 2;
Function Sum () {
$GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
}
Sum ();
echo $b;
</programlisting>
</informalexample>
<simpara>
$GLOBALS �}�C�O�@�����p�r���ަ��}�C�A �ܼƪ��W�r�|�@���b�s���Ӱ}�C�����ޡC
</simpara>
<simpara>
�t�@�ӭ��n���ܼƦ��Ľd�����O�Q�ŧi�� static ����(�R�A)���ܼơC
�R�A�ܼƥu�b��Ƥ����X�{�A ���L�b���X��Ƥ��ᥦ�̪��Ȩä��|�����C �Ҽ{�U�������p:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
$a = 0;
echo $a;
$a++;
}
</programlisting>
</informalexample>
<simpara>
�W������Ʈڥ��_���F�@�Φ]���C���i�J��ƫ� $a ���|�Q���s���w�� "0"�E $a++
�o�@�y���O�@�I�Τ]�S���]���C�����X��Ʈ� $a �N�����F�C ���F�O��Ʀ������Ϊ��p�ƾ��A
������ $a �ŧi�� static:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
static $a = 0;
echo $a;
$a++;
}
</programlisting>
</informalexample>
<simpara>
�{�b test() ��Ʒ|�L�X $a ���Ȩç�ȥ��[ 1�C </simpara>
<simpara>
�R�A�ܼƤ]�i�H�Ψӽs�g���k��� recursive function�C �o����Ʒ|�եΦۤv�C
�g�o����Ʈɭn�קK�L���`���a�եΡC �A�@�w�n����k��k�פ�C �U�ҥ� $count
�ܼƨӭp�ơA �����ƨ� 10 ���ɭԴN���X���:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
Test ();
}
$count--;
}
</programlisting>
</informalexample>
</sect1>
<sect1 id="language.variables.variable">
<title>���ܼƨӽե��ܼ�</title>
<simpara>
�������X�U�A �Τ@���ܼƨ��x�s�t�@���ܼƪ��W�r�|�O�s�{���K�C
�]���o�ˤ@�ӥi�H�ʺA�a�ե��ܼơC �@�ӥ��`���ܼƫŧi�O�o�˪�:
</simpara>
<informalexample>
<programlisting role="php">
$a = "hello";
</programlisting>
</informalexample>
<simpara>
�Ӥ@���ܼƪ��ܼƫh��s�b�䤤���ȷ����O�t�@���ܼƪ��W�r�C �b�W�Ҫ� $a ���e�Ψ� '$'
�����ܡA hello�N�|�Q�����O�t�@���ܼƪ��W�r�G
</simpara>
<informalexample>
<programlisting role="php">
$$a = "world";
</programlisting>
</informalexample>
<simpara>
��o�ج���A �@�@�ŧi�F����ܼơA �@�ӬO $a�A �t�@�ӬO $hello�C �O�H�U�������O�G
</simpara>
<informalexample>
<programlisting role="php">
echo "$a ${$a}";
</programlisting>
</informalexample>
<simpara>
�ҦL�X�Ӫ����G�M�o�@�y
</simpara>
<informalexample>
<programlisting>
echo "$a $hello";
</programlisting>
</informalexample>
<simpara>
�����G�O�@�˪��G hello world.
</simpara>
<simpara>
�b���ܼƪ��ܼƳo�k�l�Ӧs���}�C���ܡA �n�d�N $$a[1] ����ӷN��G �i�H�O�� $a[1]
�O�@���ܼƪ��W�١B�]�i�H�� $$a �O�@���ܼƦW�٦� [1] �O���ܼƤ����������� ���C
���F���T�i�D�q���A���N�ϡA �� ${$a[1]} �N���Ĥ@�ӷN��B ${$a}[1] �N���ĤG�ӡC
</simpara>
</sect1>
<sect1 id="language.variables.external">
<title>�~���ܼ�</title>
<sect2 id="language.variables.external.form">
<title>HTML �� (GET and POST)
</title>
<simpara>
������Q���浹 PHP �{���ɡA �Ҧ��b���椤���ܼƳ��۰ʵ����j�}�öǵ��{���C
���p���@�i�p�U�Ҫ�����:
If the <link linkend="ini.track-vars">track_vars</link>
configuration option is turned on, then these variables will be
located in the associative arrays
<varname>$HTTP_POST_VARS</varname>,
<varname>$HTTP_GET_VARS</varname>, and/or
<varname>$HTTP_POST_FILES</varname>, according to the
source of the variable in question.
</simpara>
<para>
For more information on these variables, please read <link
linkend="language.variables.predefined">Predefined
variables</link>.
</para>
<para>
<example>
<title>²�檺�����ܼ�</title>
<programlisting role="php">
<form action="foo.php" method="post">
Name: <input type="text" name="username"><br>
<input type="submit">
</form>
</programlisting>
</example>
</para>
<para>
�����U SUBMIT ��A PHP �|�۰ʫ��w�ܼ� $name �A �䤤�|�x�s���椤 Name: �o�@��ҧt���ȡC
PHP ���ӥs track_vars ���i�ն��A �b�}�����A�U�� POST �� GET
��k���檺�������i�H�b������ $HTTP_POST_VARS �� $HTTP_GET_VARS �}�C�����C
�n���}�o�ӥ\��i�H�� track_vars �o�ӰѼƩΨϥ� <?php_track_vars?> ���O�C
</para>
<simpara>
PHP �٥i�H���Ѫ��椤�}�C���A���ܼơC
�A�i�Q�γo�@�S�ʧ�������ܼƤ��թΪ̬O�x�s�e�\�h����ܪ��������:
</simpara>
<para>
<example>
<title>�����@�Ǫ�����
</title>
<programlisting role="php">
<form action="array.php" method="post">
Name: <input type="text" name="personal[name]"><br>
Email: <input type="text" name="personal[email]"><br>
Beer: <br>
<select multiple name="beer[]">
<option value="warthog">Warthog
<option value="guinness">Guinness
<option value="stuttgarter">Stuttgarter Schwabenbräu
</select>
<input type="submit">
</form>
</programlisting>
</example>
</para>
<para>
In PHP 3, the array form variable usage is limited to
single-dimensional arrays. In PHP 4, no such restriction applies.
</para>
<sect3 id="language.variables.external.form.submit">
<title>�� IMAGE SUBMIT ���ܼƦW</title>
<simpara>
�������ɡA �i�H���μзǪ����s�ӥιϮץN���C �y�k�p�U:</simpara>
<informalexample>
<programlisting role="php">
<input type=image src="image.gif" name="sub">
</programlisting>
</informalexample>
<simpara>
���ϥΪ̫��b�ӹϮפW�ɡA �ǥh�����A���������Ʒ|����ӷs���� sub_x �M sub_y�A
���O�O�ϥΪ̫��b�ϮפW���y�СC ����Ѥ�̥i��|���D���e�����A���������O sub.x �M
sub.y�A ���L PHP �۰ʧ�y���ܦ��F���u���C
</simpara>
</sect3>
</sect2>
<sect2 id="language.variables.external.cookies">
<title>HTTP cookies (���� ?)
</title>
<simpara>
PHP ����� <ulink
url="&spec.cookies;">Netscape's Spec</ulink>�ҩw�q�� HTTP cookies�C Cookies
�O���Ʀs��Ȥ���W���@�ؤ�k�C �o�Ǹ�ƥi�H�Ψӿ�O�Τ᪺�����C �n�]�w COOKIES �i��
SetCookie() ��ơC �]�� COOKIES �O HTTP HEADER ���Y���@�����ҥH�e�X COOKIE
���R�O�����⭶�����e��X���s�������e����C �o����M�ϥ� Header() ��ƪ�����O�@�˪��C
�ܩ�q�s�����e�^�Ӫ� COOKIES �h�� GET�B POST ��k�@�˷|�۰ʦs�b�ܼ��ءC
</simpara>
<simpara>
�p�Q�Τ@�� COOKIE �s�h�L�@�ӭȡA �u�ݦb COOKIE �W�r��[�W []�C �ܽd:
</simpara>
<informalexample>
<programlisting role="php">
SetCookie ("MyCookie[]", "Testing", time()+3600);
</programlisting>
</informalexample>
<simpara>
�`�N���D���|�κ���W�r���@�ˡA ���M�A�e�X�� COOKIE �|���N���e�P�W�� COOKIE�C
�]���b�s�g�ʪ��x�{���ɦ��ɭn�[�@�ӭp�ƾ��C �N���o�ˡG
</simpara>
<example>
<title>SetCookie �ܽd</title>
<programlisting role="php">
$Count++;
SetCookie ("Count", $Count, time()+3600);
SetCookie ("Cart[$Count]", $item, time()+3600);
</programlisting>
</example>
</sect2>
<sect2 id="language.variables.external.environment">
<title>�@�~�����ܼ�</title>
<para>
PHP �|�۰ʧ�����@�~���Ҫ���ƾ�z���@�몺�ܼƨѵ{�����ΡC
<informalexample>
<programlisting role="php">
echo $HOME; /* Shows the HOME environment variable, if set. */
</programlisting>
</informalexample>
</para>
<para>
�p�߰_���A Ū�������ܼƮɳ̦n�� <function>getenv</function>��ơA �o�O�]�� PHP
�@�ˬ�����BCOOKIE �����۰ʩw�q�ܼơA ���ɭԷ|���p�ߥΤF�ۦP���W�r�A
��ɧAŪ�����i��ä��O�u���������ܼơC ��������ܼƫh�i��
<function>putenv</function>��ơC
</para>
</sect2>
<sect2 id="language.variables.external.dot-in-names">
<title>�a '.' �����ܼ�</title>
<para>
�W PHP ���|�է��ܼƪ��W�r�A ���ѩ� PHP ���� '.'
�����S�O���N��(�걵��y)���i�H�@���ܼƦW�r�A �ҥH�a '.' �����ܼƦW�٤��� '.' �|�ܦ�
'_':
<programlisting role="php">
$varname.ext; /* invalid variable name */
</programlisting>
�W���d�Ҥ� PHP �|�z�Ѭ��@���ܼ� $varname�A �᭱��ۦA�걵�t�@���ܼ� $ext�C ��M PHP
�z�ѿ��F���Ӫ��ηN�C
</para>
</sect2>
<sect2 id="language.variables.determining-type-of">
<title>�d���ܼƪ��κA
</title>
<para>
�ѩ� PHP �|�̤��e�۰ʳ]�w�ܼƪ��κA�A
���ɭԫ����@���ݥX�@���ܼƨ쩳���ΤF���@�اκA�C ���F���Ϊ̨��o�o����T�A PHP
���n�h�Ө�ƥi�H�եΡG
<function>gettype</function>, <function>is_long</function>,
<function>is_double</function>, <function>is_string</function>,
<function>is_array</function>,�M
<function>is_object</function>.
</para>
</sect2>
</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
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->