cynic           Fri Jan 26 03:27:41 2001 EDT

  Added files:                 
    /phpdoc/cs/functions        funchand.xml 
  Log:
  
  
  translated
  

Index: phpdoc/cs/functions/funchand.xml
+++ phpdoc/cs/functions/funchand.xml
 <reference id="ref.funchand">
  <title>Funkce pro pr�ci s funkcemi</title>
  <titleabbrev>Funkce</titleabbrev>

  <partintro>
   <para>
    V�echny tyto funkce pokr�vaj� r�zn� aspekty pr�ce s funkcemi.
   </para>
  </partintro>

  <refentry id="function.call-user-func">
   <refnamediv>
    <refname>call_user_func</refname>
    <refpurpose>Zavolat u�ivatelskou funkci ur�enou prvn�m argumentem</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>mixed
       <function>call_user_func</function>
      </funcdef>
      <paramdef>string
       <parameter>function_name</parameter>
      </paramdef>
      <paramdef>mixed
       <parameter><optional>parameter</optional></parameter>
      </paramdef>
      <paramdef>mixed
       <parameter><optional>...</optional></parameter>
      </paramdef>
     </funcprototype>
    </funcsynopsis>
    <para>
     Zavol� u�ivatelsky definouvanou funkci ur�enou argumentem
     <parameter>function_name</parameter>. Zva�te n�sleduj�c� uk�zku:
     <informalexample>
      <programlisting role="php">
function barber ($type) {
    print "You wanted a $type haircut, no problem";
}
call_user_func ('barber', "mushroom");
call_user_func ('barber', "shave");
      </programlisting>
     </informalexample>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.create-function">
   <refnamediv>
    <refname>create_function</refname>
    <refpurpose>Vytvo�it anonymn� (lambda-style) funkci</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>string <function>create_function</function></funcdef>
      <paramdef>string <parameter>args</parameter></paramdef>
      <paramdef>string <parameter>code</parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <para>
     Z p�edan�ch argument� vytvo�� anonymn� funkci, a vr�t� unik�tn� n�zev t�to
     funkce. <parameter>args</parameter> se obvykle p�ed�v� jako string v
     jednoduch�ch uvozovk�ch, a doporu�ujeme to i pro <parameter>code</parameter>.
     D�vodem pro jednoduch� uvozovky je ochrana n�zv� prom�nn�ch p�ed parsov�n�m,
     pokud pou�ijete dvojit� uvozovky, budete muset oescapovat n�zvy prom�nn�ch,
     nap�. <literal>\$avar</literal>.
    </para>
    <para>
     Tuto funkci m��ete (nap��klad) pou��t k vytvo�en� funkce z dat shrom�d�n�ch
     za b�hu programu:
     <example>
      <title>
       Vytvo�en� anonymn� funkce pomoc� <function>create_function</function>
      </title>
      <programlisting role="php">
$newfunc = create_function('$a,$b','return "ln($a) + ln($b) = ".log($a * $b);');
echo "New anonymous function: $newfunc\n";
echo $newfunc(2,M_E)."\n";
// v�stup
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
      </programlisting>
     </example>
     Nebo t�eba k vytvo�en� obecn�ho handleru, kter� na p�edan� argumenty
     aplikuje sadu operac�:
     <example>
      <title>
       Vytvo�en� obecn� zpracuj�c� funkce pomoc�
       <function>create_function</function>
      </title>
      <programlisting role="php">
function process($var1, $var2, $farr) {
    for ($f=0; $f &lt; count($farr); $f++)
    echo $farr[$f]($var1,$var2)."\n";
}

// create a bunch of math functions
$f1 = 'if ($a &gt;=0) {return "b*a^2 = ".$b*sqrt($a);} else {return false;}';
$f2 = "return \"min(b^2+a, a^2,b) = \".min(\$a*\$a+\$b,\$b*\$b+\$a);";
$f3 = 'if ($a &gt; 0 &amp;&amp; $b != 0) {return "ln(a)/b = ".log($a)/$b;} else 
{return false;}';
$farr = array(
    create_function('$x,$y', 'return "some trig: ".(sin($x) + $x*cos($y));'),
    create_function('$x,$y', 'return "a hypotenuse: ".sqrt($x*$x + $y*$y);'),
    create_function('$a,$b', $f1),
    create_function('$a,$b', $f2),
    create_function('$a,$b', $f3)
    );

echo "\nUsing the first array of anonymous functions\n";
echo "parameters: 2.3445, M_PI\n";
process(2.3445, M_PI, $farr);

// now make a bunch of string processing functions
$garr = array(
    create_function('$b,$a','if (strncmp($a,$b,3) == 0) return "** \"$a\" '.
    'and \"$b\"\n** Look the same to me! (looking at the first 3 chars)";'),
    create_function('$a,$b','; return "CRCs: ".crc32($a)." , ".crc32(b);'),
    create_function('$a,$b','; return "similar(a,b) = 
".similar_text($a,$b,&amp;$p)."($p%)";')
    );
echo "\nUsing the second array of anonymous functions\n";
process("Twas brilling and the slithy toves", "Twas the night", $garr);
      </programlisting>
     </example>
     kdy� spust�te v��euveden� k�d, v�stup bude:
     <informalexample>
      <programlisting>
Using the first array of anonymous functions
parameters: 2.3445, M_PI
some trig: -1.6291725057799
a hypotenuse: 3.9199852871011
b*a^2 = 4.8103313314525
min(b^2+a, a^2,b) = 8.6382729035898
ln(a/b) = 0.27122299212594

Using the second array of anonymous functions
** "Twas the night" and "Twas brilling and the slithy toves"
** Look the same to me! (looking at the first 3 chars)
CRCs: -725381282 , 1908338681
similar(a,b) = 11(45.833333333333%)
      </programlisting>
     </informalexample>
    Ale z�ejm� nejb�n�j��m vyu�it�m lambda-style (anonymn�ch) funkc� je tvorba
    callback funkc�, nap�. pro pou�it� v <function>array_walk</function> nebo
    <function>usort</function>
    <example>
     <title>Vyu�it� anonymn�ch funkc� jako callback funkc�</title>
     <programlisting role="php">
$av = array("the ","a ","that ","this ");
array_walk($av, create_function('&amp;$v,$k','$v = $v."mango";'));
print_r($av);  // for PHP 3 use var_dump()
// outputs:
// Array
// (
//   [0] =&gt; the mango
//   [1] =&gt; a mango
//   [2] =&gt; that mango
//   [3] =&gt; this mango
// )

// an array of strings ordered from shorter to longer
$sv = array("small","larger","a big string","it is a string thing");
print_r($sv);
// outputs:
// Array
// (
//   [0] =&gt; small
//   [1] =&gt; larger
//   [2] =&gt; a big string
//   [3] =&gt; it is a string thing
// )

// sort it from longer to shorter
usort($sv, create_function('$a,$b','return strlen($b) - strlen($a);'));
print_r($sv);
// outputs:
// Array
// (
//   [0] =&gt; it is a string thing
//   [1] =&gt; a big string
//   [2] =&gt; larger
//   [3] =&gt; small
// )
     </programlisting>
    </example>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.func-get-arg">
   <refnamediv>
    <refname>func_get_arg</refname>
    <refpurpose>Vr�tit polo�ku ze seznamu argument�</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>mixed <function>func_get_arg</function></funcdef>
      <paramdef>int <parameter>arg_num</parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <simpara>
     Vrac� argument, kter� je na
     <parameter>arg_num</parameter>-t� pozici v seznamu argument� u�iavtelsky
     definovan� funkce. Argumenty funkc� se po��taj� od nuly.
     <function>func_get_arg</function> p�i vol�n� mimo definici funkce generuje
     varov�n�.
    </simpara>
    <simpara>
     Pokud je <parameter>arg_num</parameter> v�t�� ne� po�et skute�n� p�edan�ch
     argument�, vygeneruje varov�n� a vr�t� <literal>false</literal>.
    </simpara>
    <para>
     <informalexample>
      <programlisting role="php">
&lt;?php
function foo() {
     $numargs = func_num_args();
     echo "Number of arguments: $numargs&lt;br&gt;\n";
     if ($numargs &gt;= 2) {
     echo "Second argument is: " . func_get_arg (1) . "&lt;br&gt;\n";
     }
}

foo (1, 2, 3);
?&gt;
      </programlisting>
     </informalexample>
    </para>
    <simpara>
     <function>func_get_arg</function> se d� pou��t ve spojen� s
     <function>func_num_args</function> a
     <function>func_get_args</function> k tvorb� u�ivatelsky definovan�ch
     funkc�, kter� p�ij�maj� prom�nn� po�et argument�.
    </simpara>
    <note>
     <simpara>
      Tato funkce byla p�id�na v PHP 4.
     </simpara>
    </note>
   </refsect1>
  </refentry>

  <refentry id="function.func-get-args">
   <refnamediv>
    <refname>func_get_args</refname>
    <refpurpose>Vr�tit pole obsahuj�c� seznam argument� funkce</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>array <function>func_get_args</function></funcdef>
      <paramdef>void <parameter></parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <simpara>
     Vrac� pole, jeho� ka�d� prvek je odpov�daj�c� polo�kou seznamu argument�
     sou�asn� u�ivatelsky definovan� funkce. <function>func_get_args</function>
     p�i vol�n� mimo definici funkce generuje varov�n�.
    </simpara>
    <para>
     <informalexample>
      <programlisting role="php">
&lt;?php
function foo() {
    $numargs = func_num_args();
    echo "Number of arguments: $numargs&lt;br&gt;\n";
    if ($numargs &gt;= 2) {
    echo "Second argument is: " . func_get_arg (1) . "&lt;br&gt;\n";
    }
    $arg_list = func_get_args();
    for ($i = 0; $i &lt; $numargs; $i++) {
    echo "Argument $i is: " . $arg_list[$i] . "&lt;br&gt;\n";
    }
}

foo (1, 2, 3);
?&gt;
      </programlisting>
     </informalexample>
    </para>
    <simpara>
     <function>func_get_args</function> se d� pou��t ve spojen� s
     <function>func_num_args</function> a <function>func_get_arg</function> k
     tvorb� u�ivatelsky definovan�ch funkc�, kter� p�ij�maj� prom�nny po�et
     argument�.
    </simpara>
    <note>
     <simpara>
      Tato funkce byla p�id�na v PHP 4.
     </simpara>
    </note>
   </refsect1>
  </refentry>

  <refentry id="function.func-num-args">
   <refnamediv>
    <refname>func_num_args</refname>
    <refpurpose>Vr�tit po�et argument� p�edan�ch funkci</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>int <function>func_num_args</function></funcdef>
      <paramdef>void <parameter></parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <simpara>
     Vrac� po�et argument� p�edan�ch sou�asn� u�ivatelsky definovan� funkci.
     <function>Func_num_args</function> pri vol�n� mimo definici funkce generuje
     warning.
     definition.
    </simpara>
    <para>
     <informalexample>
      <programlisting role="php">
&lt;?php
function foo() {
    $numargs = func_num_args();
    echo "Number of arguments: $numargs\n";
}

foo (1, 2, 3);    // Prints 'Number of arguments: 3'
?&gt;
      </programlisting>
     </informalexample>
    </para>
    <simpara>
     <function>func_num_args</function> se d� pou�it ve spojen� s
     <function>func_get_arg</function> a <function>func_get_args</function> k
     tvorb� u�ivatelsky definovan�ch funkc�, kter� p�ij�maj� prom�nn� po�et
     argument�.
    </simpara>
    <note>
     <simpara>
      Tato funkce byla p�id�na v PHP 4.
     </simpara>
    </note>
   </refsect1>
  </refentry>

  <refentry id="function.function-exists">
   <refnamediv>
    <refname>function_exists</refname>
    <refpurpose>Vr�tit true, pokud je dan� funkce definov�na</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>bool <function>function_exists</function></funcdef>
      <paramdef>string <parameter>function_name</parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <para>
     Ov��� p��tomnost funkce <parameter>function_name</parameter> v seznamu
     definovan�ch funkc�. Pokud dan� funkce existuje, vrac� <literal>true</literal>,
     jinak <literal>false</literal>.
     <informalexample>
      <programlisting role="php">
if (function_exists('imap_open')) {
    echo "IMAP functions are available.&lt;br&gt;\n";
} else {
    echo "IMAP functions are not available.&lt;br&gt;\n";
}
      </programlisting>
     </informalexample>
     Pozn.: n�zev funkce m��e existovat i v p��pad�, �e je samotn� funkce
     nepou�iteln� kv�li konfiguraci nebo volb�m zadan�m p�i kompilaci.
    </para>
    <para>
     Viz tak� <function>method_exists</function>.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.register-shutdown-function">
   <refnamediv>
    <refname>register_shutdown_function</refname>
    <refpurpose>Zaregistrovat funkci pro proveden� p�i ukon�en� b�hu</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
    <funcsynopsis>
     <funcprototype>
      <funcdef>int
       <function>register_shutdown_function</function>
      </funcdef>
      <paramdef>string <parameter>func</parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    <simpara>
     Zaregistruje funkci udanou v <parameter>func</parameter> pro proveden�
     po dokon�en� b�hu skriptu.
    </simpara>
    <para>
     B�n� probl�my:
    </para>
    <simpara>
     Jeliko� tato funkce nem��e poslat browseru ��dn� v�stup, nebudete ji moci
     debugovat pomoc� p��kaz� jako <function>print</function> nebo
     <function>echo</function>.
    </simpara>
   </refsect1>
  </refentry>

 </reference>

<!-- 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:
-->

Reply via email to