File: pseudo-types.xml

package info (click to toggle)
php-doc 20081024-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 57,752 kB
  • ctags: 3,858
  • sloc: xml: 686,554; php: 19,446; perl: 610; cpp: 500; makefile: 336; sh: 114; awk: 28
file content (174 lines) | stat: -rw-r--r-- 4,468 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.3 $ -->
<sect1 xml:id="language.pseudo-types">
 <title>Pseudo-types and variables used in this documentation</title> 

 <sect2 xml:id="language.types.mixed">
  <title>mixed</title>

  <para>
   <literal>mixed</literal> indicates that a parameter may accept multiple (but
   not necessarily all) types.
  </para>

  <para>
   <function>gettype</function> for example will accept all PHP types, while
   <function>str_replace</function> will accept <type>string</type>s and
   <type>array</type>s.
  </para>

 </sect2>

 <sect2 xml:id="language.types.number">
  <title>number</title>

  <para>
   <literal>number</literal> indicates that a parameter can be either
   <type>integer</type> or <type>float</type>.
  </para>

 </sect2>

 <sect2 xml:id="language.types.callback">
  <title>callback</title>

  <para>
   Some functions like <function>call_user_func</function> or
   <function>usort</function> accept user-defined callback functions as a
   parameter. Callback functions can not only be simple functions, but also
   <type>object</type> methods, including static class methods.
  </para>

  <para>
   A PHP function is passed by its name as a <type>string</type>. Any built-in
   or user-defined function can be used, except language constructs such as:
   <function>array</function>, <function>echo</function>,
   <function>empty</function>, <function>eval</function>, 
   <function>exit</function>, <function>isset</function>, 
   <function>list</function>, <function>print</function> or
   <function>unset</function>.
  </para>

  <para>
   A method of an instantiated <type>object</type> is passed as an
   <type>array</type> containing an <type>object</type> at index 0 and the
   method name at index 1.
  </para>

  <para>
   Static class methods can also be passed without instantiating an
   <type>object</type> of that class by passing the class name instead of an
   <type>object</type> at index 0.
  </para>

  <para>
   Apart from common user-defined function, <function>create_function</function>
   can also be used to create an anonymous callback function.
  </para>

  <example>
   <title>
    Callback function examples
   </title>
   <programlisting role="php">
<![CDATA[
<?php 

// An example callback function
function my_callback_function() {
    echo 'hello world!';
}

// An example callback method
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>
    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> as a return type means that the return value is
   useless. <literal>void</literal> in a parameter list means that the function
   doesn't accept any parameters.
  </para>

 </sect2>

 <sect2 xml:id="language.types.dotdotdot">
  <title>...</title>

  <para>
   <parameter>$...</parameter> in function prototypes means
   <literal>and so on</literal>. This variable name is used when a function can
   take an endless number of arguments.
  </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
-->