1--TEST--
2Test is_callable() function : usage variations - on objects
3--FILE--
4<?php
5/* Prototype: bool is_callable ( mixed $var [, bool $syntax_only [, string &$callable_name]] );
6   Description: Verify that the contents of a variable can be called as a function
7                In case of objects, $var = array($SomeObject, 'MethodName')
8*/
9
10/* Prototype: void check_iscallable_objects( $methods );
11   Description: use is_callable() on given $method to check if the array
12                contains a valid method name;
13                returns true if valid function name, false otherwise
14*/
15function check_iscallable_objects( $methods ) {
16  global $loop_counter;
17  $counter = 1;
18  foreach($methods as $method) {
19    echo "-- Innerloop iteration $counter of Outerloop iteration $loop_counter --\n";
20    var_dump( is_callable($method) );
21    var_dump( is_callable($method, true) );
22    var_dump( is_callable($method, false) );
23    var_dump( is_callable($method, true, $callable_name) );
24    echo $callable_name, "\n";
25    var_dump( is_callable($method, false, $callable_name) );
26    echo $callable_name, "\n";
27    $counter++;
28  }
29}
30
31echo "\n*** Testing is_callable() on objects ***\n";
32class object_class
33{
34  public $value = 100;
35
36  /* static method */
37  static public function foo() {
38  }
39
40  public function foo1() {
41  }
42  /* function name with mixed string and integer */
43  public function x123() {
44  }
45  /* function name as NULL */
46  public function null() {
47  }
48  /* function name having boolean value */
49  public function TRUE() {
50  }
51
52  protected function foo2() {
53  }
54  private function foo3() {
55  }
56}
57/* class with no member */
58class no_member_class {
59 // no members
60}
61/* class with member as object of other class */
62class contains_object_class
63{
64   public    $class_object1;
65   var       $no_member_class_object;
66
67   public function func() {
68     echo "func() is called \n";
69   }
70
71   function __construct () {
72     $this->class_object1 = new object_class();
73     $this->no_member_class_object = new no_member_class();
74   }
75}
76/* objects of different classes */
77$obj = new contains_object_class;
78$temp_class_obj = new object_class();
79
80/* object which is unset */
81$unset_obj = new object_class();
82unset($unset_obj);
83
84/* check is_callable() on static method */
85echo "\n** Testing behavior of is_callable() on static methods **\n";
86var_dump( is_callable('object_class::foo()', true) );   //expected: true
87var_dump( is_callable('object_class::foo()') );    //expected: false
88
89echo "\n** Testing normal operations of is_callable() on objects **\n";
90$objects = array (
91  new object_class,
92  new no_member_class,
93  new contains_object_class,
94  $obj,
95  $obj->class_object1,
96  $obj->no_member_class_object,
97  $temp_class_obj,
98  @$unset_obj
99);
100
101/* loop to check whether given object/string has valid given method name
102 *  expected: true if valid callback
103 *            false otherwise
104 */
105$loop_counter = 1;
106foreach($objects as $object) {
107  echo "--- Outerloop iteration $loop_counter ---\n";
108  $methods = array (
109    array( $object, 'foo1' ),
110    array( $object, 'foo2' ),
111    array( $object, 'foo3' ),
112    array( $object, 'x123' ),
113    array( $object, 'null' ),
114    array( $object, 'TRUE' ),
115    array( $object, '123' ),
116    array( @$temp_class_obj->value, 100 ),
117    array( $object, 'func' ),
118    array( 'object_class', 'foo1' ),
119  );
120  /* use check_iscallable_objects() to check whether given object/string
121     has valid method name */
122  check_iscallable_objects($methods);
123  $loop_counter++;
124}
125
126?>
127===DONE===
128--EXPECT--
129*** Testing is_callable() on objects ***
130
131** Testing behavior of is_callable() on static methods **
132bool(true)
133bool(false)
134
135** Testing normal operations of is_callable() on objects **
136--- Outerloop iteration 1 ---
137-- Innerloop iteration 1 of Outerloop iteration 1 --
138bool(true)
139bool(true)
140bool(true)
141bool(true)
142object_class::foo1
143bool(true)
144object_class::foo1
145-- Innerloop iteration 2 of Outerloop iteration 1 --
146bool(false)
147bool(true)
148bool(false)
149bool(true)
150object_class::foo2
151bool(false)
152object_class::foo2
153-- Innerloop iteration 3 of Outerloop iteration 1 --
154bool(false)
155bool(true)
156bool(false)
157bool(true)
158object_class::foo3
159bool(false)
160object_class::foo3
161-- Innerloop iteration 4 of Outerloop iteration 1 --
162bool(true)
163bool(true)
164bool(true)
165bool(true)
166object_class::x123
167bool(true)
168object_class::x123
169-- Innerloop iteration 5 of Outerloop iteration 1 --
170bool(true)
171bool(true)
172bool(true)
173bool(true)
174object_class::null
175bool(true)
176object_class::null
177-- Innerloop iteration 6 of Outerloop iteration 1 --
178bool(true)
179bool(true)
180bool(true)
181bool(true)
182object_class::TRUE
183bool(true)
184object_class::TRUE
185-- Innerloop iteration 7 of Outerloop iteration 1 --
186bool(false)
187bool(true)
188bool(false)
189bool(true)
190object_class::123
191bool(false)
192object_class::123
193-- Innerloop iteration 8 of Outerloop iteration 1 --
194bool(false)
195bool(false)
196bool(false)
197bool(false)
198Array
199bool(false)
200Array
201-- Innerloop iteration 9 of Outerloop iteration 1 --
202bool(false)
203bool(true)
204bool(false)
205bool(true)
206object_class::func
207bool(false)
208object_class::func
209-- Innerloop iteration 10 of Outerloop iteration 1 --
210bool(true)
211bool(true)
212bool(true)
213bool(true)
214object_class::foo1
215bool(true)
216object_class::foo1
217--- Outerloop iteration 2 ---
218-- Innerloop iteration 1 of Outerloop iteration 2 --
219bool(false)
220bool(true)
221bool(false)
222bool(true)
223no_member_class::foo1
224bool(false)
225no_member_class::foo1
226-- Innerloop iteration 2 of Outerloop iteration 2 --
227bool(false)
228bool(true)
229bool(false)
230bool(true)
231no_member_class::foo2
232bool(false)
233no_member_class::foo2
234-- Innerloop iteration 3 of Outerloop iteration 2 --
235bool(false)
236bool(true)
237bool(false)
238bool(true)
239no_member_class::foo3
240bool(false)
241no_member_class::foo3
242-- Innerloop iteration 4 of Outerloop iteration 2 --
243bool(false)
244bool(true)
245bool(false)
246bool(true)
247no_member_class::x123
248bool(false)
249no_member_class::x123
250-- Innerloop iteration 5 of Outerloop iteration 2 --
251bool(false)
252bool(true)
253bool(false)
254bool(true)
255no_member_class::null
256bool(false)
257no_member_class::null
258-- Innerloop iteration 6 of Outerloop iteration 2 --
259bool(false)
260bool(true)
261bool(false)
262bool(true)
263no_member_class::TRUE
264bool(false)
265no_member_class::TRUE
266-- Innerloop iteration 7 of Outerloop iteration 2 --
267bool(false)
268bool(true)
269bool(false)
270bool(true)
271no_member_class::123
272bool(false)
273no_member_class::123
274-- Innerloop iteration 8 of Outerloop iteration 2 --
275bool(false)
276bool(false)
277bool(false)
278bool(false)
279Array
280bool(false)
281Array
282-- Innerloop iteration 9 of Outerloop iteration 2 --
283bool(false)
284bool(true)
285bool(false)
286bool(true)
287no_member_class::func
288bool(false)
289no_member_class::func
290-- Innerloop iteration 10 of Outerloop iteration 2 --
291bool(true)
292bool(true)
293bool(true)
294bool(true)
295object_class::foo1
296bool(true)
297object_class::foo1
298--- Outerloop iteration 3 ---
299-- Innerloop iteration 1 of Outerloop iteration 3 --
300bool(false)
301bool(true)
302bool(false)
303bool(true)
304contains_object_class::foo1
305bool(false)
306contains_object_class::foo1
307-- Innerloop iteration 2 of Outerloop iteration 3 --
308bool(false)
309bool(true)
310bool(false)
311bool(true)
312contains_object_class::foo2
313bool(false)
314contains_object_class::foo2
315-- Innerloop iteration 3 of Outerloop iteration 3 --
316bool(false)
317bool(true)
318bool(false)
319bool(true)
320contains_object_class::foo3
321bool(false)
322contains_object_class::foo3
323-- Innerloop iteration 4 of Outerloop iteration 3 --
324bool(false)
325bool(true)
326bool(false)
327bool(true)
328contains_object_class::x123
329bool(false)
330contains_object_class::x123
331-- Innerloop iteration 5 of Outerloop iteration 3 --
332bool(false)
333bool(true)
334bool(false)
335bool(true)
336contains_object_class::null
337bool(false)
338contains_object_class::null
339-- Innerloop iteration 6 of Outerloop iteration 3 --
340bool(false)
341bool(true)
342bool(false)
343bool(true)
344contains_object_class::TRUE
345bool(false)
346contains_object_class::TRUE
347-- Innerloop iteration 7 of Outerloop iteration 3 --
348bool(false)
349bool(true)
350bool(false)
351bool(true)
352contains_object_class::123
353bool(false)
354contains_object_class::123
355-- Innerloop iteration 8 of Outerloop iteration 3 --
356bool(false)
357bool(false)
358bool(false)
359bool(false)
360Array
361bool(false)
362Array
363-- Innerloop iteration 9 of Outerloop iteration 3 --
364bool(true)
365bool(true)
366bool(true)
367bool(true)
368contains_object_class::func
369bool(true)
370contains_object_class::func
371-- Innerloop iteration 10 of Outerloop iteration 3 --
372bool(true)
373bool(true)
374bool(true)
375bool(true)
376object_class::foo1
377bool(true)
378object_class::foo1
379--- Outerloop iteration 4 ---
380-- Innerloop iteration 1 of Outerloop iteration 4 --
381bool(false)
382bool(true)
383bool(false)
384bool(true)
385contains_object_class::foo1
386bool(false)
387contains_object_class::foo1
388-- Innerloop iteration 2 of Outerloop iteration 4 --
389bool(false)
390bool(true)
391bool(false)
392bool(true)
393contains_object_class::foo2
394bool(false)
395contains_object_class::foo2
396-- Innerloop iteration 3 of Outerloop iteration 4 --
397bool(false)
398bool(true)
399bool(false)
400bool(true)
401contains_object_class::foo3
402bool(false)
403contains_object_class::foo3
404-- Innerloop iteration 4 of Outerloop iteration 4 --
405bool(false)
406bool(true)
407bool(false)
408bool(true)
409contains_object_class::x123
410bool(false)
411contains_object_class::x123
412-- Innerloop iteration 5 of Outerloop iteration 4 --
413bool(false)
414bool(true)
415bool(false)
416bool(true)
417contains_object_class::null
418bool(false)
419contains_object_class::null
420-- Innerloop iteration 6 of Outerloop iteration 4 --
421bool(false)
422bool(true)
423bool(false)
424bool(true)
425contains_object_class::TRUE
426bool(false)
427contains_object_class::TRUE
428-- Innerloop iteration 7 of Outerloop iteration 4 --
429bool(false)
430bool(true)
431bool(false)
432bool(true)
433contains_object_class::123
434bool(false)
435contains_object_class::123
436-- Innerloop iteration 8 of Outerloop iteration 4 --
437bool(false)
438bool(false)
439bool(false)
440bool(false)
441Array
442bool(false)
443Array
444-- Innerloop iteration 9 of Outerloop iteration 4 --
445bool(true)
446bool(true)
447bool(true)
448bool(true)
449contains_object_class::func
450bool(true)
451contains_object_class::func
452-- Innerloop iteration 10 of Outerloop iteration 4 --
453bool(true)
454bool(true)
455bool(true)
456bool(true)
457object_class::foo1
458bool(true)
459object_class::foo1
460--- Outerloop iteration 5 ---
461-- Innerloop iteration 1 of Outerloop iteration 5 --
462bool(true)
463bool(true)
464bool(true)
465bool(true)
466object_class::foo1
467bool(true)
468object_class::foo1
469-- Innerloop iteration 2 of Outerloop iteration 5 --
470bool(false)
471bool(true)
472bool(false)
473bool(true)
474object_class::foo2
475bool(false)
476object_class::foo2
477-- Innerloop iteration 3 of Outerloop iteration 5 --
478bool(false)
479bool(true)
480bool(false)
481bool(true)
482object_class::foo3
483bool(false)
484object_class::foo3
485-- Innerloop iteration 4 of Outerloop iteration 5 --
486bool(true)
487bool(true)
488bool(true)
489bool(true)
490object_class::x123
491bool(true)
492object_class::x123
493-- Innerloop iteration 5 of Outerloop iteration 5 --
494bool(true)
495bool(true)
496bool(true)
497bool(true)
498object_class::null
499bool(true)
500object_class::null
501-- Innerloop iteration 6 of Outerloop iteration 5 --
502bool(true)
503bool(true)
504bool(true)
505bool(true)
506object_class::TRUE
507bool(true)
508object_class::TRUE
509-- Innerloop iteration 7 of Outerloop iteration 5 --
510bool(false)
511bool(true)
512bool(false)
513bool(true)
514object_class::123
515bool(false)
516object_class::123
517-- Innerloop iteration 8 of Outerloop iteration 5 --
518bool(false)
519bool(false)
520bool(false)
521bool(false)
522Array
523bool(false)
524Array
525-- Innerloop iteration 9 of Outerloop iteration 5 --
526bool(false)
527bool(true)
528bool(false)
529bool(true)
530object_class::func
531bool(false)
532object_class::func
533-- Innerloop iteration 10 of Outerloop iteration 5 --
534bool(true)
535bool(true)
536bool(true)
537bool(true)
538object_class::foo1
539bool(true)
540object_class::foo1
541--- Outerloop iteration 6 ---
542-- Innerloop iteration 1 of Outerloop iteration 6 --
543bool(false)
544bool(true)
545bool(false)
546bool(true)
547no_member_class::foo1
548bool(false)
549no_member_class::foo1
550-- Innerloop iteration 2 of Outerloop iteration 6 --
551bool(false)
552bool(true)
553bool(false)
554bool(true)
555no_member_class::foo2
556bool(false)
557no_member_class::foo2
558-- Innerloop iteration 3 of Outerloop iteration 6 --
559bool(false)
560bool(true)
561bool(false)
562bool(true)
563no_member_class::foo3
564bool(false)
565no_member_class::foo3
566-- Innerloop iteration 4 of Outerloop iteration 6 --
567bool(false)
568bool(true)
569bool(false)
570bool(true)
571no_member_class::x123
572bool(false)
573no_member_class::x123
574-- Innerloop iteration 5 of Outerloop iteration 6 --
575bool(false)
576bool(true)
577bool(false)
578bool(true)
579no_member_class::null
580bool(false)
581no_member_class::null
582-- Innerloop iteration 6 of Outerloop iteration 6 --
583bool(false)
584bool(true)
585bool(false)
586bool(true)
587no_member_class::TRUE
588bool(false)
589no_member_class::TRUE
590-- Innerloop iteration 7 of Outerloop iteration 6 --
591bool(false)
592bool(true)
593bool(false)
594bool(true)
595no_member_class::123
596bool(false)
597no_member_class::123
598-- Innerloop iteration 8 of Outerloop iteration 6 --
599bool(false)
600bool(false)
601bool(false)
602bool(false)
603Array
604bool(false)
605Array
606-- Innerloop iteration 9 of Outerloop iteration 6 --
607bool(false)
608bool(true)
609bool(false)
610bool(true)
611no_member_class::func
612bool(false)
613no_member_class::func
614-- Innerloop iteration 10 of Outerloop iteration 6 --
615bool(true)
616bool(true)
617bool(true)
618bool(true)
619object_class::foo1
620bool(true)
621object_class::foo1
622--- Outerloop iteration 7 ---
623-- Innerloop iteration 1 of Outerloop iteration 7 --
624bool(true)
625bool(true)
626bool(true)
627bool(true)
628object_class::foo1
629bool(true)
630object_class::foo1
631-- Innerloop iteration 2 of Outerloop iteration 7 --
632bool(false)
633bool(true)
634bool(false)
635bool(true)
636object_class::foo2
637bool(false)
638object_class::foo2
639-- Innerloop iteration 3 of Outerloop iteration 7 --
640bool(false)
641bool(true)
642bool(false)
643bool(true)
644object_class::foo3
645bool(false)
646object_class::foo3
647-- Innerloop iteration 4 of Outerloop iteration 7 --
648bool(true)
649bool(true)
650bool(true)
651bool(true)
652object_class::x123
653bool(true)
654object_class::x123
655-- Innerloop iteration 5 of Outerloop iteration 7 --
656bool(true)
657bool(true)
658bool(true)
659bool(true)
660object_class::null
661bool(true)
662object_class::null
663-- Innerloop iteration 6 of Outerloop iteration 7 --
664bool(true)
665bool(true)
666bool(true)
667bool(true)
668object_class::TRUE
669bool(true)
670object_class::TRUE
671-- Innerloop iteration 7 of Outerloop iteration 7 --
672bool(false)
673bool(true)
674bool(false)
675bool(true)
676object_class::123
677bool(false)
678object_class::123
679-- Innerloop iteration 8 of Outerloop iteration 7 --
680bool(false)
681bool(false)
682bool(false)
683bool(false)
684Array
685bool(false)
686Array
687-- Innerloop iteration 9 of Outerloop iteration 7 --
688bool(false)
689bool(true)
690bool(false)
691bool(true)
692object_class::func
693bool(false)
694object_class::func
695-- Innerloop iteration 10 of Outerloop iteration 7 --
696bool(true)
697bool(true)
698bool(true)
699bool(true)
700object_class::foo1
701bool(true)
702object_class::foo1
703--- Outerloop iteration 8 ---
704-- Innerloop iteration 1 of Outerloop iteration 8 --
705bool(false)
706bool(false)
707bool(false)
708bool(false)
709Array
710bool(false)
711Array
712-- Innerloop iteration 2 of Outerloop iteration 8 --
713bool(false)
714bool(false)
715bool(false)
716bool(false)
717Array
718bool(false)
719Array
720-- Innerloop iteration 3 of Outerloop iteration 8 --
721bool(false)
722bool(false)
723bool(false)
724bool(false)
725Array
726bool(false)
727Array
728-- Innerloop iteration 4 of Outerloop iteration 8 --
729bool(false)
730bool(false)
731bool(false)
732bool(false)
733Array
734bool(false)
735Array
736-- Innerloop iteration 5 of Outerloop iteration 8 --
737bool(false)
738bool(false)
739bool(false)
740bool(false)
741Array
742bool(false)
743Array
744-- Innerloop iteration 6 of Outerloop iteration 8 --
745bool(false)
746bool(false)
747bool(false)
748bool(false)
749Array
750bool(false)
751Array
752-- Innerloop iteration 7 of Outerloop iteration 8 --
753bool(false)
754bool(false)
755bool(false)
756bool(false)
757Array
758bool(false)
759Array
760-- Innerloop iteration 8 of Outerloop iteration 8 --
761bool(false)
762bool(false)
763bool(false)
764bool(false)
765Array
766bool(false)
767Array
768-- Innerloop iteration 9 of Outerloop iteration 8 --
769bool(false)
770bool(false)
771bool(false)
772bool(false)
773Array
774bool(false)
775Array
776-- Innerloop iteration 10 of Outerloop iteration 8 --
777bool(true)
778bool(true)
779bool(true)
780bool(true)
781object_class::foo1
782bool(true)
783object_class::foo1
784===DONE===
785