Files
doc-fr/reference/funchand/functions/call-user-func-array.xml
2021-09-24 04:13:47 +01:00

209 lines
4.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: eec6a4a36bf452bf271f116e7b6b9bb09d1181c3 Maintainer: yannick Status: ready -->
<!-- Reviewed: yes -->
<refentry xml:id="function.call-user-func-array" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>call_user_func_array</refname>
<refpurpose>Appelle une fonction de rappel avec les paramètres rassemblés en tableau</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>call_user_func_array</methodname>
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
<methodparam><type>array</type><parameter>args</parameter></methodparam>
</methodsynopsis>
<para>
Appelle la fonction de rappel <parameter>callback</parameter>
fournie avec les paramètres <parameter>args</parameter>,
rassemblés dans un tableau.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>callback</parameter></term>
<listitem>
<para>
La fonction de rappel à appeler.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>args</parameter></term>
<listitem>
<para>
Les paramètres à passer à la fonction de rappel,
sous la forme d'un tableau indexé.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Retourne la valeur retournée par la fonction
de rappel, ou &false; si une erreur survient.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Exemple avec <function>call_user_func_array</function></title>
<programlisting role="php">
<![CDATA[
<?php
function foobar($arg, $arg2) {
echo __FUNCTION__, " got $arg and $arg2\n";
}
class foo {
function bar($arg, $arg2) {
echo __METHOD__, " got $arg and $arg2\n";
}
}
// Appel de la fonction foobar() avec 2 arguments
call_user_func_array("foobar", array("one", "two"));
// Appel de la méthode $foo->bar() avec 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
foobar got one and two
foo::bar got three and four
]]>
</screen>
</example>
<example>
<title>Exemple avec <function>call_user_func_array</function> en utilisant un espace de nom</title>
<programlisting role="php">
<![CDATA[
<?php
namespace Foobar;
class Foo {
static public function test($name) {
print "Bonjour {$name}!\n";
}
}
call_user_func_array(__NAMESPACE__ .'\Foo::test', array('Hannes'));
call_user_func_array(array(__NAMESPACE__ .'\Foo', 'test'), array('Philip'));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Bonjour Hannes!
Bonjour Philip!
]]>
</screen>
</example>
<example>
<title>Utilisation d'une fonction lambda</title>
<programlisting role="php">
<![CDATA[
<?php
$func = function($arg1, $arg2) {
return $arg1 * $arg2;
};
var_dump(call_user_func_array($func, array(2, 4)));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(8)
]]>
</screen>
</example>
<example>
<title>En passant une valeur par référence</title>
<programlisting role="php">
<![CDATA[
<?php
function mega(&$a){
$a = 55;
echo "function mega \$a=$a\n";
}
$bar = 77;
call_user_func_array('mega',array(&$bar));
echo "global \$bar=$bar\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
function mega $a=55
global $bar=55
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.func-callback-exceptions;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>call_user_func</function></member>
<member><methodname>ReflectionFunction::invokeArgs</methodname></member>
<member><methodname>ReflectionMethod::invokeArgs</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- 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:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->