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