cvs: phpdoc-zh /language/types pseudo-types.xml

From: Date: Fri, 26 Dec 2008 12:06:01 +0000
Subject: cvs: phpdoc-zh /language/types pseudo-types.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-3147@lists.php.net to get a copy of this message
eniac2008 Fri Dec 26 12:06:01 2008 UTC Added files: /phpdoc-zh/language/types pseudo-types.xml Log: New File, sync with EN-Revision 1.3 http://cvs.php.net/viewvc.cgi/phpdoc-zh/language/types/pseudo-types.xml?view=markup&rev=1.1 Index: phpdoc-zh/language/types/pseudo-types.xml +++ phpdoc-zh/language/types/pseudo-types.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Author: eniac2008 $ --> <!-- $Revision: 1.1 $--> <!-- EN-Revision: 1.3 Maintainer: Altair Status: ready --> <!-- CREDITS: Altair --> <sect1 xml:id="language.pseudo-types"> <title>本文档中使用的伪类型</title> <sect2 xml:id="language.types.mixed"> <title>mixed</title> <para> <literal>mixed</literal> 说明一个参数可以接受多种不同的(但并不必须是所有的)类型。 </para> <para> 例如 <function>gettype</function> 可以接受所有的 PHP 类型,<function>str_replace</function> 可以接受字符串和数组。 </para> </sect2> <sect2 xml:id="language.types.number"> <title>number</title> <para> <literal>number</literal> 说明一个参数可以是 <type>integer</type> 或者 <type>float</type>。 </para> </sect2> <sect2 xml:id="language.types.callback"> <title>callback</title> <para> 有些诸如 <function>call_user_function</function> 或 <function>usort</function> 的函数接受用户自定义的函数作为一个参数。Callback 函数不仅可以是一个简单的函数,它还可以是一个对象的方法,包括静态类的方法。 </para> <para> 一个 PHP 函数用函数名字符串来传递。可以传递任何内置的或者用户自定义的函数,除了语言结构如 <function>array</function>,<function>echo</function>,<function>empty</function>,<function>eval</function>,<function>exit</function>,<function>isset</function>,<function>list</function>,<function>print</function> 和 <function>unset</function>。 </para> <para> 一个对象的方法以数组的形式来传递,数组的下标 0 指明对象名,下标 1 指明方法名。 </para> <para> 对于没有实例化为对象的静态类,要传递其方法,将数组 0 下标指明的对象名换成该类的名称即可。 </para> <para> 除了普通的用户定义的函数外,也可以使用<function>create_function</function>来创建一个匿名的回调函数(callback)。 </para> <example> <title> 回调函数(callback)示例 </title> <programlisting role="php"> <![CDATA[ <?php // 普通的回调函数 function my_callback_function() { echo 'hello world!'; } // 回调方法 class MyClass { static function myCallbackMethod() { echo 'Hello World!'; } } // Type 1: Simple callback call_user_func('my_callback_function'); // Type 2: Static class method call call_user_func(array('MyClass', 'myCallbackMethod')); // Type 3: Object method call $obj = new MyClass(); call_user_func(array($obj, 'myCallbackMethod')); // Type 4: Static class method call (As of PHP 5.2.3) call_user_func('MyClass::myCallbackMethod'); // Type 5: Relative static class method call (As of PHP 5.3.0) class A { public static function who() { echo "A\n"; } } class B extends A { public static function who() { echo "B\n"; } } call_user_func(array('B', 'parent::who')); // A ?> ]]> </programlisting> </example> <note> <simpara> 在 PHP4 中,必须使用引用来创建一个指向实际<type>object</type>,而不是它的一个拷贝。详情请见<link linkend="language.references">引用的解释</link>。 In PHP4, it was necessary to use a reference to create a callback that points to the actual <type>object</type>, and not a copy of it. For more details, see <link linkend="language.references">References Explained</link>. </simpara> </note> </sect2> <sect2 xml:id="language.types.void"> <title>void</title> <para> <literal>void</literal> 作为返回类型意味着函数的返回值是无用的。<literal>void</literal>作为参数列表意味着函数不接受任何参数。 </para> </sect2> <sect2 xml:id="language.types.dotdotdot"> <title>...</title> <para> 在函数原型中,<parameter>$...</parameter> 表示<literal>等等</literal>的意思。当一个函数可以接受任意个参数时使用此变量名。 </para> </sect2> </sect1> <!-- 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:"../../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 -->

« previous php.doc.zh (#3147) next »