4
4
<refnamediv >
5
5
<refname >is_callable</refname >
6
6
<refpurpose >
7
- Verify that a value can be called as a function from the current scope.
7
+ Verify that a value can be called as a function from the current scope
8
8
</refpurpose >
9
9
</refnamediv >
10
10
77
77
<programlisting role =" php" >
78
78
<![CDATA[
79
79
<?php
80
- // How to check a variable to see if it can be called
81
- // as a function.
80
+ // How to check a variable to see if it can be called
81
+ // as a function.
82
82
83
83
//
84
- // Simple variable containing a function
84
+ // Simple variable containing a function
85
85
//
86
86
87
- function someFunction()
88
- {
89
- }
87
+ function someFunction() {}
90
88
91
89
$functionVariable = 'someFunction';
92
90
93
- var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
91
+ var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
94
92
95
- echo $callable_name, "\n"; // someFunction
93
+ echo $callable_name, "\n"; // someFunction
96
94
97
95
//
98
- // Array containing a method
96
+ // Array containing a method
99
97
//
100
98
101
- class someClass {
102
-
103
- function someMethod()
104
- {
105
- }
106
-
99
+ class someClass
100
+ {
101
+ public function someMethod() {}
107
102
}
108
103
109
104
$anObject = new someClass();
110
105
111
- $methodVariable = array( $anObject, 'someMethod') ;
106
+ $methodVariable = [ $anObject, 'someMethod'] ;
112
107
113
- var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
108
+ var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
114
109
115
- echo $callable_name, "\n"; // someClass::someMethod
110
+ echo $callable_name, "\n"; // someClass::someMethod
116
111
117
112
?>
118
113
]]>
@@ -131,13 +126,16 @@ echo $callable_name, "\n"; // someClass::someMethod
131
126
class Foo
132
127
{
133
128
public function __construct() {}
129
+
134
130
public function foo() {}
135
131
}
136
132
137
133
var_dump(
138
- is_callable(array( 'Foo', '__construct') ),
139
- is_callable(array( 'Foo', 'foo') )
134
+ is_callable([ 'Foo', '__construct'] ),
135
+ is_callable([ 'Foo', 'foo'] )
140
136
);
137
+
138
+ ?>
141
139
]]>
142
140
</programlisting >
143
141
&example.outputs;
0 commit comments