mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Parameters are not passed by reference (bug #24931)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165569 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
cf4527aa7e
commit
ab9ab888cc
1 changed files with 30 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/funchand.xml, last change in rev 1.1 -->
|
||||
<refentry id="function.call-user-func">
|
||||
<refnamediv>
|
||||
|
@ -41,17 +41,15 @@ call_user_func('barber', "shave");
|
|||
Object methods may also be invoked statically using this function
|
||||
by passing <literal>array($objectname, $methodname)</literal> to
|
||||
the <parameter>function</parameter> parameter.
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class myclass {
|
||||
function say_hello()
|
||||
{
|
||||
echo "Hello!\n";
|
||||
}
|
||||
function say_hello()
|
||||
{
|
||||
echo "Hello!\n";
|
||||
}
|
||||
}
|
||||
|
||||
$classname = "myclass";
|
||||
|
@ -62,6 +60,31 @@ call_user_func(array($classname, 'say_hello'));
|
|||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Note that the parameters for <function>call_user_func</function> are not
|
||||
passed by reference.
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function increment(&$var)
|
||||
{
|
||||
$var++;
|
||||
}
|
||||
|
||||
$a = 0;
|
||||
call_user_func('increment', $a);
|
||||
echo $a; // 0
|
||||
|
||||
call_user_func_array('increment', array(&$a)); // You can use this instead
|
||||
echo $a; // 1
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
See also:
|
||||
<function>is_callable</function>, and
|
||||
|
|
Loading…
Reference in a new issue