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