upgrade examples

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@283362 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Damien Seguy 2009-07-02 21:52:02 +00:00
parent 76e4b9cefc
commit 39f34e31d4
4 changed files with 86 additions and 23 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.22 $ -->
<!-- $Revision: 1.23 $ -->
<refentry xml:id="function.call-user-func-array" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>call_user_func_array</refname>
@ -69,8 +69,8 @@ function debug($var, $val)
echo "***\n";
}
$c = mysql_connect();
$host = $_SERVER["SERVER_NAME"];
$c = new StdClass();
$host = $_SERVER["PHP_SELF"];
call_user_func_array('debug', array("host", $host));
call_user_func_array('debug', array("c", $c));
@ -78,6 +78,11 @@ call_user_func_array('debug', array("_POST", $_POST));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
]]>
</screen>
</example>
<example>
<title><function>call_user_func_array</function> using namespace name</title>
@ -95,15 +100,20 @@ class Foo {
// As of PHP 5.3.0
call_user_func_array(__NAMESPACE__ .'\Foo::test', array('Hannes'));
// Hello Hannes!
// As of PHP 5.3.0
call_user_func_array(array(__NAMESPACE__ .'\Foo', 'test'), array('Philip'));
// Hello Philip!
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Hello Hannes!
Hello Philip!
]]>
</screen>
</example>
<example>
<title>Using lambda function</title>
@ -116,11 +126,16 @@ $func = function($arg1, $arg2) {
};
var_dump(call_user_func_array($func, array(2, 4))); /* As of PHP 5.3.0 */
// int(8)
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(8)
]]>
</screen>
</example>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.22 $ -->
<!-- $Revision: 1.23 $ -->
<refentry xml:id="function.call-user-func" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>call_user_func</refname>
@ -46,10 +46,12 @@
<para>
Note that the parameters for <function>call_user_func</function> are
not passed by reference.
<informalexample>
<example>
<title><function>call_user_func</function> example and references</title>
<programlisting role="php">
<![CDATA[
<?php
error_reporting(E_ALL);
function increment(&$var)
{
$var++;
@ -57,14 +59,21 @@ function increment(&$var)
$a = 0;
call_user_func('increment', $a);
echo $a; // 0
echo $a."\n";
call_user_func_array('increment', array(&$a)); // You can use this instead
echo $a; // 1
call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
echo $a."\n";
?>
]]>
</programlisting>
</informalexample>
&example.outputs;
<screen>
<![CDATA[
0
1
]]>
</screen>
</example>
</para>
</note>
</listitem>
@ -90,13 +99,20 @@ echo $a; // 1
<?php
function barber($type)
{
echo "You wanted a $type haircut, no problem";
echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
You wanted a mushroom haircut, no problem
You wanted a shave haircut, no problem
]]>
</screen>
</example>
<example>
<title><function>call_user_func</function> using namespace name</title>
@ -113,16 +129,21 @@ class Foo {
}
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
// Hello world!
call_user_func(array(__NAMESPACE__ .'\Foo', 'test')); // As of PHP 5.3.0
// Hello world!
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Hello world!
Hello world!
]]>
</screen>
</example>
<example>
<title>Using a class method</title>
<title>Using a class method with <function>call_user_func</function></title>
<programlisting role="php">
<![CDATA[
<?php
@ -146,19 +167,30 @@ call_user_func(array($myobject, 'say_hello'));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Hello!
Hello!
Hello!
]]>
</screen>
</example>
<example>
<title>Using lambda function</title>
<title>Using lambda function with <function>call_user_func</function></title>
<programlisting role="php">
<![CDATA[
<?php
call_user_func(function($arg) { print "[$arg]\n"; }, 'test'); /* As of PHP 5.3.0 */
// [test]
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
[test]
]]>
</screen>
</example>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.func-get-args" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>func_get_args</refname>
@ -86,6 +86,16 @@ foo(1, 2, 3);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Number of arguments: 3<br />
Second argument is: 2<br />
Argument 0 is: 1<br />
Argument 1 is: 2<br />
Argument 2 is: 3<br />
]]>
</screen>
</example>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.func-num-args" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>func_num_args</refname>
@ -75,10 +75,16 @@ function foo()
echo "Number of arguments: $numargs\n";
}
foo(1, 2, 3); // Prints 'Number of arguments: 3'
foo(1, 2, 3);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Number of arguments: 3
]]>
</screen>
</example>
</para>
</refsect1>