luk             Fri Apr 26 16:35:28 2002 EDT

  Added files:                 
    /phpdoc/cs/language variables.xml 

  Modified files:              
    /phpdoc/cs/language control-structures.xml 
  Log:
  
  
  
Index: phpdoc/cs/language/control-structures.xml
diff -u phpdoc/cs/language/control-structures.xml:1.4 
phpdoc/cs/language/control-structures.xml:1.5
--- phpdoc/cs/language/control-structures.xml:1.4       Thu Apr 25 17:58:13 2002
+++ phpdoc/cs/language/control-structures.xml   Fri Apr 26 16:35:27 2002
@@ -854,27 +854,25 @@
     <link linkend="control-structures.declare.ticks">ticks</link>)
    </para>
    <para>
-    The <literal>statement</literal> part of the
-    <literal>declare</literal> block will be executed - how
-    it is executed and what side-effects occur during execution
-    may depend on the directive set in the
-    <literal>directive</literal> block.
+    ��st <literal>statement</literal> bloku <literal>declare</literal>
+    bude provedena - jak bude provedena a jak� vedlej�� efekty nastanou
+    b�hem prov�d�n� m��e z�le�et na direktiv� nastaven� v bloku
+    <literal>directive</literal>.
    </para>
    <sect2 id="control-structures.declare.ticks">
     <title>Ticks</title>
-    <para>A tick is an event that occurs for every
-    <replaceable>N</replaceable> low-level statements executed
-    by the parser within the <literal>declare</literal> block.
-    The value for <replaceable>N</replaceable> is specified
-    using <literal>ticks=<replaceable>N</replaceable></literal>
-    within the <literal>declare</literal> blocks's
-    <literal>directive</literal> section.
+    <para>Tick je ud�lost, kter� nastane pro ka�d�ch
+    <replaceable>N</replaceable> n�zko�rov�ov�ch konstrukt� proveden�ch
+    parserem uvnit� bloku <literal>declare</literal>. Hodnota
+    <replaceable>N</replaceable> je specifikov�na pomoc�
+    <literal>ticks=<replaceable>N</replaceable></literal> uvnit� sekce
+    <literal>directive</literal> bloku <literal>declare</literal>.
    </para>
    <para>
-    The event(s) that occurs on each tick is specified using the
-    <function>register_tick_function</function>. See the example 
-    below for more details. Note that more than one event can occur
-    for each tick.
+    Ud�lost(i), kter� nastane p�i ka�d�m ticku, se specifikuje pomoc�
+    <function>register_tick_function</function>. V�ce podrobnost� - viz
+    p��klad n��e. Uv�domte si, �e na ka�d� tick m��e nastat v�ce ne� jedna
+    ud�lost.
    </para>
    <para>
     <example>

Index: phpdoc/cs/language/variables.xml
+++ phpdoc/cs/language/variables.xml
<?xml version="1.0" encoding="iso-8859-2"?>
<!-- EN-Revision: 1.45 Maintainer: luk Status: mixed -->

 <chapter id="language.variables">
  <title>Prom�nn�</title>
  
  <sect1 id="language.variables.basics">
   <title>Z�klady</title>

   <simpara>
    Prom�nn� jsou v PHP reprezentov�ny znakem dolaru, n�sledovan�m n�zvem
    p��slu�n� prom�nn�. V n�zvech prom�nn�ch se rozli�uje velikost p�smen.
   </simpara>

   <para>
    N�zvy prom�nn�ch jsou pod��zeny stejn�m pravidl�m jako jin� n�v�t�
    v PHP. Platn� n�zev prom�nn� za��n� p�smenem nebo podtr��tkem,
    n�sledovan�m libovoln�m po�tem p�smen, ��slic nebo potr��tek. Jako
    regul�rn� v�raz to lze zapsat takto:
    '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
   </para>
   
   <note>
    <simpara>
     Pro na�e ��ely zde budeme za p�smena pova�ovat znaky a-z, A-Z
     a ASCII znaky od 127 do 255 (0x7f-0xff).
    </simpara>
   </note>

   <para>
    <informalexample>
     <programlisting role="php"> 
<![CDATA[
$var = "Bob";
$Var = "Joe";
echo "$var, $Var";      // vyp��e "Bob, Joe"

$4site = 'not yet';     // neplatn�; za��n� ��slic�
$_4site = 'not yet';    // platn�; za��n� podtr��tkem
$t�yte = 'mansikka';    // platn�; '�' je ASCII 228.
]]>
     </programlisting>
    </informalexample>
   </para>

   <para>
    V PHP 3 maj� prom�nn� v�dy p�i�azenu hodnotu. To znamen�, �e kdy�
    p�i�ad�te v�raz do prom�nn�, cel� hodnota p�vodn�ho v�razu se
    zkop�ruje do c�lov� prom�nn�. Tedy, nap��klad, po p�i�azen� hodnoty
    jedn� prom�nn� do druh�, zm�na jedn� z nich se na druh� neprojev�.
    V�ce informac� o tomto zp�sobu p�i�azen� viz
    <link linkend="language.expressions">V�razy</link>.
   </para>
   <para>
    PHP nab�z� jin� zp�sob p�i�azen� hodnot prom�nn�m:
    <emphasis>p�i�azen� odkazu</emphasis>. To znamen�, �e nov� prom�nn�
    jednodu�e odkazuje (jin�mi slovy, "st�v� se aliasem" nebo "ukazuje na")
    na p�vodn� prom�nnou. Zm�ny na nov� prom�nn� se projev� na t� p�vodn�
    a naopak. To tak� znamen�, �e se nic nekop�ruje; proto je p�i�azen�
    rychlej��. Av�ak toto zrychlen� bude zjistiteln� pouze v t�sn�ch cyklech
    nebo p�i p�i�azov�n� velk�ch pol� �i objekt�.
   </para>
   <para>
    Pro p�i�azen� odkazu sta�� jednodu�e p�ed prom�nnou, kter� bude
    p�i�azov�na (zdrojov� prom�nn�), p�ed�adit ampersand (&amp;). Nap��klad
    n�sleduj�c� kus k�du vyp��e dvakr�t 'Jmenuji se Bob':

    <informalexample>
     <programlisting role="php">
<![CDATA[
<?php
$foo = 'Bob';              // P�i�ad� hodnotu 'Bob' do $foo
$bar = &$foo;              // Odkaz $foo p�es $bar.
$bar = "Jmenuji se $bar";  // Zm�na $bar...
echo $bar;
echo $foo;                 // $foo je tak� zm�n�no.
?>
]]>
     </programlisting>
    </informalexample>
   </para>

   <para>
    Jednou z d�le�it�ch v�c�, kter� je t�eba si uv�domit, je to, �e p�es
    odkazy lze p�i�azovat pouze pojmenovan� prom�nn�.
    <informalexample>
     <programlisting role="php">
<![CDATA[
<?php
$foo = 25;
$bar = &$foo;      // Toto je platn� p�i�azen�.
$bar = &(24 * 7);  // Neplatn�; odkazuje se nepojmenovan� v�raz.

function test()
{
   return 25;
}

$bar = &test();    // Neplatn�.
?>
]]>
     </programlisting>
    </informalexample>
   </para>

  </sect1>

  <sect1 id="language.variables.predefined">
   <title>P�eddefinovan� prom�nn�</title>
   
   <simpara>
    PHP poskytuje velk� mno�stv� p�eddefinovan�ch prom�nn�ch jak�mukoli
    skriptu, kter� prov�d�. Mnoho t�chto prom�nn�ch, bohu�el, nem��e b�t
    pln� zdokumentov�no, proto�e z�visej� na tom, na kter�m serveru skript
    b��, na verzi a nastaven� serveru a dal��ch faktorech. N�kter� z t�chto
    prom�nn�ch nebudou dostupn�, kdy� PHP pob�� z p��kazov� ��dky. Seznam
    prom�nn�ch - viz sekce 
    <link linkend="reserved.variables">P�eddefinovan� prom�nn�</link>.
   </simpara>

   <warning>
    <simpara>
     V PHP 4.2.0 a pozd�j��ch se zm�nila implicitn� sada p�eddefinovan�ch
     prom�nn�ch, kter� jsou glob�ln� dostupn�. Individu�ln� vstupn� a
     serverov� prom�nn� se <emphasis>implicitn�</emphasis> neum�s�uj� do
     glob�ln�ho kontextu; nam�sto toho jsou v n�sleduj�c�ch
     <link linkend="language.variables.superglobals">superglob�ln�ch
     pol�ch</link>.
    </simpara>
    <simpara>
     M��ete v�ak st�le vynutit star� chov�n� nastaven�m
     <link linkend="ini.register-globals">register_globals</link> v souboru
     &php.ini; na 'On'.
    </simpara>
    <simpara>
     Pro v�ce informac� a pozad� t�chto zm�n pros�m nahl�dn�te do
     <ulink url="&url.php.release4.1.0;">PHP 4.1.0 Release Announcement</ulink>.
    </simpara>
   </warning>

   <simpara>
    Od verze 4.1.0 poskytuje PHP sadu p�eddefinovan�ch pol�, obsahuj�c�ch
    prom�nn� WWW serveru (pokud to jde), prost�ed� a u�ivatelsk�ho vstupu.
    Tato nov� pole maj� tu zvl�tnost, �e jsou automaticky glob�ln� -- tedy
    nap�. automaticky dostupn� v ka�d�m kontextu. Z tohoto d�vodu jsou
    �asto zn�ma jako "autoglob�ln�" nebo "superglob�ln�". (V PHP neexistuje
    mechanismus pro u�ivatelskou definici superglob�ln�ch prom�nn�ch).
    Superglob�ln� prom�nn� jsou vyps�ny n��e; pro seznam jejich obsah� a
    dal�� diskusi o p�eddefinovan�ch prom�nn�ch v PHP a jejich charakteru
    v�ak mus�te nahl�dnout do ��sti 
    <link linkend="reserved.variables">P�eddefinovan� prom�nn�</link>.
   </simpara>

   <variablelist id="language.variables.superglobals">
    <title>PHP superglobals (superglob�ln� prom�nn�)</title>
    <varlistentry>
     <term><link linkend="reserved.variables.globals">$GLOBALS</link></term>
     <listitem>
      <simpara>
       Obsahuje odkaz na ka�dou prom�nnou, kter� je moment�ln� dostupn�
       v glob�ln�m kontextu skriptu. Kl��i tohoto pole jsou n�zvy glob�ln�ch
       prom�nn�ch.
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.server">$_SERVER</link></term>
     <listitem>
      <simpara>
       Prom�nn� nastavovan� WWW serveru nebo jinak p��mo spjat� s prov�d�c�m
       prost�ed�m aktu�ln�ho skriptu. Analogick� star�mu poli
       <varname>$HTTP_SERVER_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�).
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.get">$_GET</link></term>
     <listitem>
      <simpara>
       Prom�nn� poskytovan� skriptu p�es HTTP GET. Analogick� star�mu poli
       <varname>$HTTP_GET_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�).
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.post">$_POST</link></term>
     <listitem>
      <simpara>
       Prom�nn� poskytovan� skriptu p�es HTTP POST. Analogick� star�mu poli
       <varname>$HTTP_POST_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�).
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.cookies">$_COOKIE</link></term>
     <listitem>
      <simpara>
       Prom�nn� poskytovan� skriptu p�es HTTP cookies. Analogick� star�mu poli
       <varname>$HTTP_COOKIE_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�).
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.files">$_FILES</link></term>
     <listitem>
      <simpara>
       Prom�nn� poskytovan� skriptu p�es HTTP post uploady soubor�. Analogick�
       uploads. Analogick� star�mu poli
       <varname>$HTTP_POST_FILES</varname> (kter� je st�le dostupn�, ale
       zavr�en�). V�ce informac� - viz
       <link linkend="features.file-upload.post-method">Upload metodou
       POST</link>.
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.environment">$_ENV</link></term>
     <listitem>
      <simpara>Prom�nn� poskytovan� skriptu z prost�ed�. Analogick� star�mu
      poli <varname>$HTTP_ENV_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�).
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.request">$_REQUEST</link></term>
     <listitem>
      <simpara>
       Prom�nn� poskytovan� skriptu p�es libovoln� vstupn� mechanismus a
       kter�m proto nelze d�v��ovat. Pozn.: p�i b�hu z p��kazov� ��dky zde
       <emphasis>nebudou</emphasis> p��tomny polo�ky <varname>argv</varname>
       a <varname>argc</varname>; nach�zej� se v poli
       <varname>$_SERVER</varname>. P��tomnost a po�ad� prom�nn�ch v tomto
       poli se definuje podle konfigura�n� direktivy
       <link linkend="ini.variables-order">variables_order</link>. Toto pole
       nem� p��mou analogii ve verz�ch PHP p�ed 4.1.0.
      </simpara>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><link linkend="reserved.variables.session">$_SESSION</link></term>
     <listitem>
      <simpara>
       Prom�nn�, kter� jsou moment�ln� registrov�ny v aktu�ln� relaci skriptu.
       Analogick� star�mu poli
       <varname>$HTTP_SESSION_VARS</varname> (kter� je st�le dostupn�, ale
       zavr�en�). V�ce informac� - viz <link
       linkend="ref.session">Funkce pro obsluhu sessions</link>.
      </simpara>
     </listitem>
    </varlistentry>
   </variablelist>

  </sect1>


  <sect1 id="language.variables.scope">
   <title>Kontext ("scope") prom�nn�</title>

   <simpara>
    Kontext prom�nn� je oblast, ve kter� je definov�na. V�t�ina prom�nn�ch
    v PHP m� pouze jedin� kontext. Ten zahrnuje i soubory vlo�en� pomoc�
    "include" nebo "require". Nap��klad:
   </simpara>
   <informalexample>
    <programlisting role="php">
<![CDATA[
$a = 1;
include "b.inc";
]]>
    </programlisting>
   </informalexample>
   <simpara>
    Zde bude prom�nn� <varname>$a</varname> dostupn� ve vlo�en�m skriptu
    <filename>b.inc</filename>. Av�ak uvnit� u�ivatelsky definovan�ch funkc�
    se zakl�d� jejich lok�ln� kontext. Jak�koli prom�nn� pou�it� uvnit�
    funkce je implicitn� omezena na tento m�stn� kontext. Nap��klad:
   </simpara>
    
   <informalexample>
    <programlisting role="php"> 
<![CDATA[
$a = 1; /* glob�ln� kontext */ 

function Test()
{ 
    echo $a; /* odkaz na prom�nnou v lok�ln�m kontextu */ 
} 

Test();
]]>
    </programlisting>
   </informalexample>

   <simpara>
    Tento skript nevyprodukuje ��dn� v�stup, proto�e konstrukt "echo"
    odkazuje na lok�ln� verzi prom�nn� <varname>$a</varname>, a ta nem�
    v tomto kontextu p�i�azenu ��dnou hodnotu. M��ete si v�imnout, �e to je
    trochu jin� ne� v jazyce C, kde jsou glob�ln� funkce automaticky
    dostupn� ve funkc�ch, pokud nejsou specificky zast�n�ny lok�ln� definic�.
    To m��e zp�sobit probl�my t�m, �e �lov�k m��e necht�n� zm�nit glob�ln�
    prom�nnou. V PHP mus� b�t glob�ln� prom�nn� deklarov�ny uvnit� funkce
    jako glob�ln�, pokud se v n� maj� pou��vat. P��klad:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;

    $b = $a + $b;
} 

Sum();
echo $b;
]]>
    </programlisting>
   </informalexample>

   <simpara>
    V��e uveden� skript vytiskne &quot;3&quot;. Deklarac�
    <varname>$a</varname> a <varname>$b</varname> ve funkci jako glob�ln�ch
    prom�nn�ch se dos�hne toho, �e p�i odkazov�n� na prom�nn� se pracuje
    s jejich glob�ln� verz�. Po�et glob�ln�ch prom�nn�ch, se kter�mi lze ve
    funkci manipulovat, nen� omezen.
   </simpara>

   <simpara>
    Druh�m zp�sobem, jak p�istupovat k prom�nn�m z glob�ln�ho kontextu, je
    pou�it� speci�ln�ho pole <varname>$GLOBALS</varname>, definovan�ho
    v PHP. P�edchoz� p��klad lze p�epsat:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
$a = 1;
$b = 2;

function Sum()
{
    $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
} 

Sum();
echo $b;
]]>
    </programlisting>
   </informalexample>

   <simpara>
    Pole <varname>$GLOBALS</varname> je asociativn� pole s n�zvem glob�ln�
    prom�nn� jako kl��em a obsahem p��slu�n� prom�nn� jako obsahem elementu
    pole.
   </simpara>

   <simpara>
    Jinou d�le�itou vlastnost� rozli�ov�n� kontext� prom�nn�ch je mo�nost
    pou��v�n� <emphasis>static</emphasis> prom�nn�ch. Statick� prom�nn�
    existuje pouze v lok�ln�m kontextu funkce, ale neztr�c� svoji hodnotu,
    pokud prov�d�n� programu tento kontext opust�. Uva�ujme n�sleduj�c�
    p��klad:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
function Test ()
{
    $a = 0;
    echo $a;
    $a++;
}
]]>
    </programlisting>
   </informalexample>

   <simpara>
    Tato funkce je pon�kud neu�ite�n�, nebo� p�i ka�d�m vol�n� nastavuje
    <varname>$a</varname> na <literal>0</literal> a tiskne &quot;0&quot;.
    Konstrukt <varname>$a</varname>++, kter� inkrementuje prom�nnou, nem�
    ��dn� v�znam, proto�e p�i skon�en� vykon�v�n� funkce se obsah prom�nn�    
    <varname>$a</varname> ztr�c�. Aby m�la funkce skute�n� v�znam ��ta�e a
    hodnota se neztr�cela, deklaruje se prom�nn� <varname>$a</varname>
    jako statick�:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
function Test()
{
    static $a = 0;
    echo $a;
    $a++;
}
]]>
    </programlisting>
   </informalexample>

   <simpara>
    Nyn� se p�i ka�d�m vol�n� funkce Test() vytiskne hodnota prom�nn�
    <varname>$a</varname> a inkrementuje se.
   </simpara>

   <simpara>
    Static variables also provide one way to deal with recursive
    functions. A recursive function is one which calls itself.  Care
    must be taken when writing a recursive function because it is
    possible to make it recurse indefinitely.  You must make sure you
    have an adequate way of terminating the recursion.  The following
    simple function recursively counts to 10, using the static
    variable <varname>$count</varname> to know when to stop:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
function Test()
{
    static $count = 0;

    $count++;
    echo $count;
    if ($count < 10) {
        Test ();
    }
    $count--;
}
]]>
    </programlisting>
   </informalexample>

  </sect1>

  <sect1 id="language.variables.variable">
   <title>Variable variables</title>

   <simpara>
    Sometimes it is convenient to be able to have variable variable
    names.  That is, a variable name which can be set and used
    dynamically.  A normal variable is set with a statement such as:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
$a = "hello";
]]>
    </programlisting>
   </informalexample>

   <simpara>
    A variable variable takes the value of a variable and treats that
    as the name of a variable.  In the above example,
    <emphasis>hello</emphasis>, can be used as the name of a variable
    by using two dollar signs. i.e.
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
$$a = "world";
]]>
    </programlisting>
   </informalexample>

   <simpara>
    At this point two variables have been defined and stored in the
    PHP symbol tree: <varname>$a</varname> with contents "hello" and
    <varname>$hello</varname> with contents "world".  Therefore, this
    statement:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
echo "$a ${$a}";
]]>
    </programlisting>
   </informalexample>

   <simpara>
    produces the exact same output as:
   </simpara>

   <informalexample>
    <programlisting role="php">
<![CDATA[
echo "$a $hello";
]]>
    </programlisting>
   </informalexample>

   <simpara>
    i.e. they both produce: <computeroutput>hello world</computeroutput>.
   </simpara>

   <simpara>
    In order to use variable variables with arrays, you have to
    resolve an ambiguity problem.  That is, if you write
    <varname>$$a[1]</varname> then the parser needs to know if you
    meant to use <varname>$a[1]</varname> as a variable, or if you
    wanted <varname>$$a</varname> as the variable and then the [1]
    index from that variable.  The syntax for resolving this ambiguity
    is: <varname>${$a[1]}</varname> for the first case and
    <varname>${$a}[1]</varname> for the second.
   </simpara>
  
  </sect1>

  <sect1 id="language.variables.external">
   <title>Variables from outside PHP</title>

   <sect2 id="language.variables.external.form">
    <title>HTML Forms (GET and POST)</title>

    <simpara>
     When a form is submitted to a PHP script, any variables from that
     form will be automatically made available to the script by
     PHP. 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>Simple form variable</title>
      <programlisting role="php">
<![CDATA[
<form action="foo.php" method="post">
    Name: <input type="text" name="username"><br>
    <input type="submit">
</form>
]]>
      </programlisting>
     </example>
    </para>

    <para>
     When the above form is submitted, the value from the text input
     will be available in
     <varname>$HTTP_POST_VARS['username']</varname>. If the <link
     linkend="ini.register-globals">register_globals</link>
     configuration directive is turned on, then the variable will also
     be available as <varname>$username</varname> in the global scope.
    </para>

    <note>
     <para>
      The <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> 
      configuration directive affects Get, Post and Cookie values.  If 
      turned on, value (It's "PHP!") will automagically become (It\'s \"PHP!\").
      Escaping is needed for DB insertion.  Also see
      <function>addslashes</function>, <function>stripslashes</function> and 
      <link linkend="ini.magic-quotes-sybase">magic_quotes_sybase</link>.
     </para>
    </note>
    
    <simpara>
     PHP also understands arrays in the context of form variables 
     (see the <link linkend="faq.html">related faq</link>).  You may, 
     for example, group related variables together, or use this 
     feature to retrieve values from a multiple select input:
    </simpara>

    <para>
     <example>
      <title>More complex form variables</title>
      <programlisting role="php">
<![CDATA[
<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 variable names</title>

     <simpara>
      When submitting a form, it is possible to use an image instead
      of the standard submit button with a tag like:</simpara>

     <informalexample>
      <programlisting role="php">
<![CDATA[
<input type="image" src="image.gif" name="sub">
]]>
      </programlisting>
     </informalexample>

     <simpara>
      When the user clicks somewhere on the image, the accompanying
      form will be transmitted to the server with two additional
      variables, sub_x and sub_y. These contain the coordinates of the
      user click within the image.  The experienced may note that the
      actual variable names sent by the browser contains a period
      rather than an underscore, but PHP converts the period to an
      underscore automatically.
     </simpara>
    </sect3>

   </sect2>

   <sect2 id="language.variables.external.cookies">
    <title>HTTP Cookies</title>

    <simpara>
     PHP transparently supports HTTP cookies as defined by <ulink
     url="&spec.cookies;">Netscape's Spec</ulink>.  Cookies are a
     mechanism for storing data in the remote browser and thus
     tracking or identifying return users.  You can set cookies using
     the <function>setcookie</function> function.  Cookies are part of
     the HTTP header, so the SetCookie function must be called before
     any output is sent to the browser.  This is the same restriction
     as for the <function>header</function> function.  Any cookies
     sent to you from the client will automatically be turned into a
     PHP variable just like GET and POST method data.</simpara>

    <simpara>
     If you wish to assign multiple values to a single cookie, just
     add <emphasis>[]</emphasis> to the cookie name.  For
     example:
    </simpara>

    <informalexample>
     <programlisting role="php">
<![CDATA[
setcookie("MyCookie[]", "Testing", time()+3600);
]]>
     </programlisting>
    </informalexample>

    <simpara>
     Note that a cookie will replace a previous cookie by the same
     name in your browser unless the path or domain is different.  So,
     for a shopping cart application you may want to keep a counter
     and pass this along.  i.e.
    </simpara>

    <example>
     <title>SetCookie Example</title>
     <programlisting role="php">
<![CDATA[
$Count++;
setcookie("Count", $Count, time()+3600);
setcookie("Cart[$Count]", $item, time()+3600);
]]>
     </programlisting>
    </example>

   </sect2>

   <sect2 id="language.variables.external.environment">
    <title>Environment variables</title>

    <para>
     PHP automatically makes environment variables available as normal
     PHP variables.
     
     <informalexample>
      <programlisting role="php">
<![CDATA[
echo $HOME;  /* Shows the HOME environment variable, if set. */
]]>
      </programlisting>
     </informalexample>
    </para>

    <para>
     Since information coming in via GET, POST and Cookie mechanisms
     also automatically create PHP variables, it is sometimes best to
     explicitly read a variable from the environment in order to make
     sure that you are getting the right version.  The
     <function>getenv</function> function can be used for this.  You
     can also set an environment variable with the
     <function>putenv</function> function.
    </para>
   </sect2>

   <sect2 id="language.variables.external.dot-in-names">
    <title>Dots in incoming variable names</title>

    <para>
     Typically, PHP does not alter the names of variables when they
     are passed into a script. However, it should be noted that the
     dot (period, full stop) is not a valid character in a PHP
     variable name. For the reason, look at it:
     <programlisting role="php">
<![CDATA[
$varname.ext;  /* invalid variable name */
]]>
     </programlisting>
     Now, what the parser sees is a variable named
     <varname>$varname</varname>, followed by the string concatenation
     operator, followed by the barestring (i.e. unquoted string which
     doesn't match any known key or reserved words) 'ext'. Obviously,
     this doesn't have the intended result.
    </para>

    <para>
     For this reason, it is important to note that PHP will
     automatically replace any dots in incoming variable names with
     underscores.
    </para>

   </sect2>

   <sect2 id="language.variables.determining-type-of">
    <title>Determining variable types</title>

    <para>
     Because PHP determines the types of variables and converts them
     (generally) as needed, it is not always obvious what type a given
     variable is at any one time.  PHP includes several functions
     which find out what type a variable is. They are
     <function>gettype</function>, <function>is_array</function>,
     <function>is_float</function>, <function>is_int</function>,
     <function>is_object</function>, and
     <function>is_string</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
 indent-tabs-mode:nil
 sgml-parent-document:nil
 sgml-default-dtd-file:"../manual.ced"
 sgml-exposed-tags:nil
 sgml-local-catalogs:nil
 sgml-local-ecat-files:nil
 End:
 -->

Reply via email to