Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 5589

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>call_user_func</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Function Handling Functions"
HREF="ref.funchand.html"><LINK
REL="PREVIOUS"
TITLE="call_user_func_array"
HREF="function.call-user-func-array.html"><LINK
REL="NEXT"
TITLE="create_function"
HREF="function.create-function.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.call-user-func-array.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.create-function.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.call-user-func"
></A
>call_user_func</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN62637"
></A
><P
>    (PHP 3 &#62;= 3.0.3, PHP 4, PHP 5)</P
>call_user_func&nbsp;--&nbsp;Call a user function given by the first parameter</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN62640"
></A
><H2
>说明</H2
>mixed <B
CLASS="methodname"
>call_user_func</B
> ( callback function [, mixed parameter [, mixed ...]] )<BR
></BR
><P
>&#13;   Call a user defined function given by the <CODE
CLASS="parameter"
>function</CODE
>
   parameter.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN62656"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>function</CODE
></DT
><DD
><P
>&#13;       The function to be called. Class methods may also be invoked
       statically using this function by passing
       <TT
CLASS="literal"
>array($classname, $methodname)</TT
> to this parameter.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>parameter</CODE
></DT
><DD
><P
>&#13;       Zero or more parameters to be passed to the function.
      </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
        Note that the parameters for <B
CLASS="function"
>call_user_func()</B
> are
        not passed by reference.
        <DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN62674"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">increment</font><font color="#007700">(&amp;</font><font color="#0000BB">$var</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$var</font><font color="#007700">++;<br />}<br /><br /></font><font color="#0000BB">$a </font><font color="#007700">= </font><font color="#0000BB">0</font><font color="#007700">;<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(</font><font color="#DD0000">'increment'</font><font color="#007700">, </font><font color="#0000BB">$a</font><font color="#007700">);<br />echo </font><font color="#0000BB">$a</font><font color="#007700">; </font><font color="#FF8000">// 0<br /><br /></font><font color="#0000BB">call_user_func_array</font><font color="#007700">(</font><font color="#DD0000">'increment'</font><font color="#007700">, array(&amp;</font><font color="#0000BB">$a</font><font color="#007700">)); </font><font color="#FF8000">// You can use this instead<br /></font><font color="#007700">echo </font><font color="#0000BB">$a</font><font color="#007700">; </font><font color="#FF8000">// 1<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
></P
></DIV
>
       </P
></BLOCKQUOTE
></DIV
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN62676"
></A
><H2
>返回值</H2
><P
>&#13;   Returns the function result, or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on error.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN62680"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN62683"
></A
><P
><B
>例 1. <B
CLASS="function"
>call_user_func()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">barber</font><font color="#007700">(</font><font color="#0000BB">$type</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"You wanted a $type haircut, no problem"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(</font><font color="#DD0000">'barber'</font><font color="#007700">, </font><font color="#DD0000">"mushroom"</font><font color="#007700">);<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(</font><font color="#DD0000">'barber'</font><font color="#007700">, </font><font color="#DD0000">"shave"</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN62687"
></A
><P
><B
>例 2. Using a class method</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">class </font><font color="#0000BB">myclass </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">say_hello</font><font color="#007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Hello!\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></font><font color="#0000BB">$classname </font><font color="#007700">= </font><font color="#DD0000">"myclass"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(array(</font><font color="#0000BB">$classname</font><font color="#007700">, </font><font color="#DD0000">'say_hello'</font><font color="#007700">));<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN62690"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.call-user-func-array.html"
><B
CLASS="function"
>call_user_func_array()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.is-callable.html"
><B
CLASS="function"
>is_callable()</B
></A
></TD
></TR
><TR
><TD
>有关 <A
HREF="language.pseudo-types.html#language.types.callback"
>callback</A
> 类型的信息</TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.call-user-func-array.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.create-function.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>call_user_func_array</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.funchand.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>create_function</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>