reference/outcontrol/functions/ob-list-handlers.xml
87a266cdd7f53bc86cd22d21af289b9a75f57f94
...
...
@@ -25,11 +25,30 @@
25
25
<refsect1 role="returnvalues">
26
26
&reftitle.returnvalues;
27
27
<para>
28
-
This will return an array with the output handlers in use (if any). If
29
-
<link linkend="ini.output-buffering">output_buffering</link> is enabled or
30
-
an anonymous function was used with <function>ob_start</function>,
31
-
<function>ob_list_handlers</function> will return "default output
32
-
handler".
28
+
This will return an array with the output handlers in use (if any).
29
+
</para>
30
+
<para>
31
+
If <link linkend="ini.output-buffering">output_buffering</link> is enabled
32
+
and no <link linkend="ini.output-handler">output_handler</link> is set,
33
+
or no callback or &null; was passed to <function>ob_start</function>,
34
+
<literal>"default output handler"</literal> is returned.
35
+
Enabling <link linkend="ini.output-buffering">output_buffering</link>
36
+
and setting an <link linkend="ini.output-handler">output_handler</link>
37
+
is equivalent to passing
38
+
an <link linkend="functions.internal">internal (built-in) function</link>
39
+
to <function>ob_start</function>.
40
+
</para>
41
+
<para>
42
+
If a <type>callable</type> was passed to <function>ob_start</function>,
43
+
the <link linkend="language.namespaces.basics">fully qualified name</link>
44
+
of the <type>callable</type> is returned.
45
+
If the <type>callable</type> is an object implementing
46
+
<link linkend="language.oop5.magic.invoke">__invoke()</link>,
47
+
the <link linkend="language.namespaces.basics">fully qualified name</link>
48
+
of the object's <link linkend="language.oop5.magic.invoke">__invoke()</link>
49
+
method is returned.
50
+
If the <type>callable</type> is a <classname>Closure</classname>,
51
+
<literal>"Closure::__invoke"</literal> is returned.
33
52
</para>
34
53
</refsect1>
35
54

...
...
@@ -41,17 +60,71 @@
41
60
<programlisting role="php">
42
61
<![CDATA[
43
62
<?php
44
-
//using output_buffering=On
45
-
print_r(ob_list_handlers());
63
+
// using output_buffering=On, no output_handler set
64
+
var_dump(ob_list_handlers());
46
65
ob_end_flush();
47
66

48
-
ob_start("ob_gzhandler");
49
-
print_r(ob_list_handlers());
67
+
// no callback or null
68
+
ob_start();
69
+
var_dump(ob_list_handlers());
50
70
ob_end_flush();
51
71

52
-
// anonymous functions
72
+
// anonymous function
53
73
ob_start(function($string) { return $string; });
54
-
print_r(ob_list_handlers());
74
+
var_dump(ob_list_handlers());
75
+
ob_end_flush();
76
+

77
+
// arrow function
78
+
ob_start(fn($string) => $string);
79
+
var_dump(ob_list_handlers());
80
+
ob_end_flush();
81
+

82
+
// first class callable
83
+
$firstClassCallable = userDefinedFunction(...);
84
+

85
+
ob_start([$firstClassCallable, '__invoke']);
86
+
var_dump(ob_list_handlers());
87
+
ob_end_flush();
88
+

89
+
// internal (built-in) function
90
+
ob_start('print_r');
91
+
var_dump(ob_list_handlers());
92
+
ob_end_flush();
93
+

94
+
// user-defined function
95
+
function userDefinedFunction($string, $flags) { return $string; };
96
+

97
+
ob_start('userDefinedFunction');
98
+
var_dump(ob_list_handlers());
99
+
ob_end_flush();
100
+

101
+
class MyClass {
102
+
public static function staticHandle($string) {
103
+
return $string;
104
+
}
105
+

106
+
public static function handle($string) {
107
+
return $string;
108
+
}
109
+

110
+
public function __invoke($string) {
111
+
return $string;
112
+
}
113
+
}
114
+

115
+
// class and static method
116
+
ob_start(['MyClass','staticHandle']);
117
+
var_dump(ob_list_handlers());
118
+
ob_end_flush();
119
+

120
+
// object and non-static method
121
+
ob_start([new MyClass,'handle']);
122
+
var_dump(ob_list_handlers());
123
+
ob_end_flush();
124
+

125
+
// invokable object
126
+
ob_start(new MyClass);
127
+
var_dump(ob_list_handlers());
55
128
ob_end_flush();
56
129
?>
57
130
]]>
...
...
@@ -59,20 +132,46 @@ ob_end_flush();
59
132
&example.outputs;
60
133
<screen>
61
134
<![CDATA[
62
-
Array
63
-
(
64
-
[0] => default output handler
65
-
)
66
-

67
-
Array
68
-
(
69
-
[0] => ob_gzhandler
70
-
)
71
-

72
-
Array
73
-
(
74
-
[0] => Closure::__invoke
75
-
)
135
+
array(1) {
136
+
[0]=>
137
+
string(22) "default output handler"
138
+
}
139
+
array(1) {
140
+
[0]=>
141
+
string(22) "default output handler"
142
+
}
143
+
array(1) {
144
+
[0]=>
145
+
string(7) "print_r"
146
+
}
147
+
array(1) {
148
+
[0]=>
149
+
string(19) "userDefinedFunction"
150
+
}
151
+
array(1) {
152
+
[0]=>
153
+
string(17) "Closure::__invoke"
154
+
}
155
+
array(1) {
156
+
[0]=>
157
+
string(17) "Closure::__invoke"
158
+
}
159
+
array(1) {
160
+
[0]=>
161
+
string(17) "Closure::__invoke"
162
+
}
163
+
array(1) {
164
+
[0]=>
165
+
string(21) "MyClass::staticHandle"
166
+
}
167
+
array(1) {
168
+
[0]=>
169
+
string(15) "MyClass::handle"
170
+
}
171
+
array(1) {
172
+
[0]=>
173
+
string(17) "MyClass::__invoke"
174
+
}
76
175
]]>
77
176
</screen>
78
177
</example>
79
178