<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >本文档中使用的伪类型</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="类型" HREF="language.types.html"><LINK REL="PREVIOUS" TITLE="NULL" HREF="language.types.null.html"><LINK REL="NEXT" TITLE="类型戏法" HREF="language.types.type-juggling.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="sect1" 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="language.types.null.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >章 11. 类型</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.types.type-juggling.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.pseudo-types" >本文档中使用的伪类型</A ></H1 ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.types.mixed" >mixed</A ></H2 ><P > <TT CLASS="literal" >mixed</TT > 说明一个参数可以接受多种不同的(但并不必须是所有的)类型。 </P ><P > 例如 <A HREF="function.gettype.html" ><B CLASS="function" >gettype()</B ></A > 可以接受所有的 PHP 类型,<A HREF="function.str-replace.html" ><B CLASS="function" >str_replace()</B ></A > 可以接受字符串和数组。 </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.types.number" >number</A ></H2 ><P > <TT CLASS="literal" >number</TT > 说明一个参数可以是 <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A > 或者 <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A >。 </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.types.callback" >callback</A ></H2 ><P > 有些诸如 <B CLASS="function" >call_user_function()</B > 或 <A HREF="function.usort.html" ><B CLASS="function" >usort()</B ></A > 的函数接受用户自定义的函数作为一个参数。Callback 函数不仅可以是一个简单的函数,它还可以是一个对象的方法,包括静态类的方法。 </P ><P > 一个 PHP 函数用函数名字符串来传递。可以传递任何内置的或者用户自定义的函数,除了 <A HREF="function.array.html" ><B CLASS="function" >array()</B ></A >,<A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A >,<A HREF="function.empty.html" ><B CLASS="function" >empty()</B ></A >,<A HREF="function.eval.html" ><B CLASS="function" >eval()</B ></A >,<A HREF="function.exit.html" ><B CLASS="function" >exit()</B ></A >,<A HREF="function.isset.html" ><B CLASS="function" >isset()</B ></A >,<A HREF="function.list.html" ><B CLASS="function" >list()</B ></A >,<A HREF="function.print.html" ><B CLASS="function" >print()</B ></A > 和 <A HREF="function.unset.html" ><B CLASS="function" >unset()</B ></A >。 </P ><P > 一个对象的方法以数组的形式来传递,数组的下标 0 指明对象名,下标 1 指明方法名。 </P ><P > 对于没有实例化为对象的静态类,要传递其方法,将数组 0 下标指明的对象名换成该类的名称即可。 </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3467" ></A ><P ><B >例 11-13. Callback 函数实例</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// An example callback function<br /></font><font color="#007700">function </font><font color="#0000BB">my_callback_function</font><font color="#007700">() {<br /> echo </font><font color="#DD0000">'hello world!'</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">// An example callback method<br /></font><font color="#007700">class </font><font color="#0000BB">MyClass </font><font color="#007700">{<br /> function </font><font color="#0000BB">myCallbackMethod</font><font color="#007700">() {<br /> echo </font><font color="#DD0000">'Hello World!'</font><font color="#007700">;<br /> }<br />}<br /><br /></font><font color="#FF8000">// Type 1: Simple callback<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(</font><font color="#DD0000">'my_callback_function'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Type 2: Static class method call<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(array(</font><font color="#DD0000">'MyClass'</font><font color="#007700">, </font><font color="#DD0000">'myCallbackMethod'</font><font color="#007700">));<br /><br /></font><font color="#FF8000">// Type 3: Object method call<br /></font><font color="#0000BB">$obj </font><font color="#007700">= new </font><font color="#0000BB">MyClass</font><font color="#007700">();<br /></font><font color="#0000BB">call_user_func</font><font color="#007700">(array(</font><font color="#0000BB">$obj</font><font color="#007700">, </font><font color="#DD0000">'myCallbackMethod'</font><font color="#007700">));<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></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="language.types.null.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="language.types.type-juggling.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >NULL</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.types.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >类型戏法</TD ></TR ></TABLE ></DIV ></BODY ></HTML >