Annotation of embedaddon/php/ext/standard/tests/general_functions/is_callable_basic2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test is_callable() function : usage variations - on objects
3: --INI--
4: precision=14
5: error_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: */
18: function 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:
34: echo "\n*** Testing is_callable() on objects ***\n";
35: class 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 */
61: class no_member_class {
62: // no members
63: }
64: /* class with member as object of other class */
65: class 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 contains_object_class () {
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();
85: unset($unset_obj);
86:
87: /* check is_callable() on static method */
88: echo "\n** Testing behavior of is_callable() on static methods **\n";
89: var_dump( is_callable('object_class::foo()', true) ); //expected: true
90: var_dump( is_callable('object_class::foo()') ); //expected: false
91:
92: echo "\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;
109: foreach($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 **
135: bool(true)
136: bool(false)
137:
138: ** Testing normal operations of is_callable() on objects **
139: --- Outerloop iteration 1 ---
140: -- Innerloop iteration 1 of Outerloop iteration 1 --
141: bool(true)
142: bool(true)
143: bool(true)
144: bool(true)
145: object_class::foo1
146: bool(true)
147: object_class::foo1
148: -- Innerloop iteration 2 of Outerloop iteration 1 --
149: bool(false)
150: bool(true)
151: bool(false)
152: bool(true)
153: object_class::foo2
154: bool(false)
155: object_class::foo2
156: -- Innerloop iteration 3 of Outerloop iteration 1 --
157: bool(false)
158: bool(true)
159: bool(false)
160: bool(true)
161: object_class::foo3
162: bool(false)
163: object_class::foo3
164: -- Innerloop iteration 4 of Outerloop iteration 1 --
165: bool(true)
166: bool(true)
167: bool(true)
168: bool(true)
169: object_class::x123
170: bool(true)
171: object_class::x123
172: -- Innerloop iteration 5 of Outerloop iteration 1 --
173: bool(true)
174: bool(true)
175: bool(true)
176: bool(true)
177: object_class::null
178: bool(true)
179: object_class::null
180: -- Innerloop iteration 6 of Outerloop iteration 1 --
181: bool(true)
182: bool(true)
183: bool(true)
184: bool(true)
185: object_class::TRUE
186: bool(true)
187: object_class::TRUE
188: -- Innerloop iteration 7 of Outerloop iteration 1 --
189: bool(false)
190: bool(true)
191: bool(false)
192: bool(true)
193: object_class::123
194: bool(false)
195: object_class::123
196: -- Innerloop iteration 8 of Outerloop iteration 1 --
197: bool(false)
198: bool(false)
199: bool(false)
200: bool(false)
201: Array
202: bool(false)
203: Array
204: -- Innerloop iteration 9 of Outerloop iteration 1 --
205: bool(false)
206: bool(true)
207: bool(false)
208: bool(true)
209: object_class::func
210: bool(false)
211: object_class::func
212: -- Innerloop iteration 10 of Outerloop iteration 1 --
213: bool(true)
214: bool(true)
215: bool(true)
216: bool(true)
217: object_class::foo1
218: bool(true)
219: object_class::foo1
220: --- Outerloop iteration 2 ---
221: -- Innerloop iteration 1 of Outerloop iteration 2 --
222: bool(false)
223: bool(true)
224: bool(false)
225: bool(true)
226: no_member_class::foo1
227: bool(false)
228: no_member_class::foo1
229: -- Innerloop iteration 2 of Outerloop iteration 2 --
230: bool(false)
231: bool(true)
232: bool(false)
233: bool(true)
234: no_member_class::foo2
235: bool(false)
236: no_member_class::foo2
237: -- Innerloop iteration 3 of Outerloop iteration 2 --
238: bool(false)
239: bool(true)
240: bool(false)
241: bool(true)
242: no_member_class::foo3
243: bool(false)
244: no_member_class::foo3
245: -- Innerloop iteration 4 of Outerloop iteration 2 --
246: bool(false)
247: bool(true)
248: bool(false)
249: bool(true)
250: no_member_class::x123
251: bool(false)
252: no_member_class::x123
253: -- Innerloop iteration 5 of Outerloop iteration 2 --
254: bool(false)
255: bool(true)
256: bool(false)
257: bool(true)
258: no_member_class::null
259: bool(false)
260: no_member_class::null
261: -- Innerloop iteration 6 of Outerloop iteration 2 --
262: bool(false)
263: bool(true)
264: bool(false)
265: bool(true)
266: no_member_class::TRUE
267: bool(false)
268: no_member_class::TRUE
269: -- Innerloop iteration 7 of Outerloop iteration 2 --
270: bool(false)
271: bool(true)
272: bool(false)
273: bool(true)
274: no_member_class::123
275: bool(false)
276: no_member_class::123
277: -- Innerloop iteration 8 of Outerloop iteration 2 --
278: bool(false)
279: bool(false)
280: bool(false)
281: bool(false)
282: Array
283: bool(false)
284: Array
285: -- Innerloop iteration 9 of Outerloop iteration 2 --
286: bool(false)
287: bool(true)
288: bool(false)
289: bool(true)
290: no_member_class::func
291: bool(false)
292: no_member_class::func
293: -- Innerloop iteration 10 of Outerloop iteration 2 --
294: bool(true)
295: bool(true)
296: bool(true)
297: bool(true)
298: object_class::foo1
299: bool(true)
300: object_class::foo1
301: --- Outerloop iteration 3 ---
302: -- Innerloop iteration 1 of Outerloop iteration 3 --
303: bool(false)
304: bool(true)
305: bool(false)
306: bool(true)
307: contains_object_class::foo1
308: bool(false)
309: contains_object_class::foo1
310: -- Innerloop iteration 2 of Outerloop iteration 3 --
311: bool(false)
312: bool(true)
313: bool(false)
314: bool(true)
315: contains_object_class::foo2
316: bool(false)
317: contains_object_class::foo2
318: -- Innerloop iteration 3 of Outerloop iteration 3 --
319: bool(false)
320: bool(true)
321: bool(false)
322: bool(true)
323: contains_object_class::foo3
324: bool(false)
325: contains_object_class::foo3
326: -- Innerloop iteration 4 of Outerloop iteration 3 --
327: bool(false)
328: bool(true)
329: bool(false)
330: bool(true)
331: contains_object_class::x123
332: bool(false)
333: contains_object_class::x123
334: -- Innerloop iteration 5 of Outerloop iteration 3 --
335: bool(false)
336: bool(true)
337: bool(false)
338: bool(true)
339: contains_object_class::null
340: bool(false)
341: contains_object_class::null
342: -- Innerloop iteration 6 of Outerloop iteration 3 --
343: bool(false)
344: bool(true)
345: bool(false)
346: bool(true)
347: contains_object_class::TRUE
348: bool(false)
349: contains_object_class::TRUE
350: -- Innerloop iteration 7 of Outerloop iteration 3 --
351: bool(false)
352: bool(true)
353: bool(false)
354: bool(true)
355: contains_object_class::123
356: bool(false)
357: contains_object_class::123
358: -- Innerloop iteration 8 of Outerloop iteration 3 --
359: bool(false)
360: bool(false)
361: bool(false)
362: bool(false)
363: Array
364: bool(false)
365: Array
366: -- Innerloop iteration 9 of Outerloop iteration 3 --
367: bool(true)
368: bool(true)
369: bool(true)
370: bool(true)
371: contains_object_class::func
372: bool(true)
373: contains_object_class::func
374: -- Innerloop iteration 10 of Outerloop iteration 3 --
375: bool(true)
376: bool(true)
377: bool(true)
378: bool(true)
379: object_class::foo1
380: bool(true)
381: object_class::foo1
382: --- Outerloop iteration 4 ---
383: -- Innerloop iteration 1 of Outerloop iteration 4 --
384: bool(false)
385: bool(true)
386: bool(false)
387: bool(true)
388: contains_object_class::foo1
389: bool(false)
390: contains_object_class::foo1
391: -- Innerloop iteration 2 of Outerloop iteration 4 --
392: bool(false)
393: bool(true)
394: bool(false)
395: bool(true)
396: contains_object_class::foo2
397: bool(false)
398: contains_object_class::foo2
399: -- Innerloop iteration 3 of Outerloop iteration 4 --
400: bool(false)
401: bool(true)
402: bool(false)
403: bool(true)
404: contains_object_class::foo3
405: bool(false)
406: contains_object_class::foo3
407: -- Innerloop iteration 4 of Outerloop iteration 4 --
408: bool(false)
409: bool(true)
410: bool(false)
411: bool(true)
412: contains_object_class::x123
413: bool(false)
414: contains_object_class::x123
415: -- Innerloop iteration 5 of Outerloop iteration 4 --
416: bool(false)
417: bool(true)
418: bool(false)
419: bool(true)
420: contains_object_class::null
421: bool(false)
422: contains_object_class::null
423: -- Innerloop iteration 6 of Outerloop iteration 4 --
424: bool(false)
425: bool(true)
426: bool(false)
427: bool(true)
428: contains_object_class::TRUE
429: bool(false)
430: contains_object_class::TRUE
431: -- Innerloop iteration 7 of Outerloop iteration 4 --
432: bool(false)
433: bool(true)
434: bool(false)
435: bool(true)
436: contains_object_class::123
437: bool(false)
438: contains_object_class::123
439: -- Innerloop iteration 8 of Outerloop iteration 4 --
440: bool(false)
441: bool(false)
442: bool(false)
443: bool(false)
444: Array
445: bool(false)
446: Array
447: -- Innerloop iteration 9 of Outerloop iteration 4 --
448: bool(true)
449: bool(true)
450: bool(true)
451: bool(true)
452: contains_object_class::func
453: bool(true)
454: contains_object_class::func
455: -- Innerloop iteration 10 of Outerloop iteration 4 --
456: bool(true)
457: bool(true)
458: bool(true)
459: bool(true)
460: object_class::foo1
461: bool(true)
462: object_class::foo1
463: --- Outerloop iteration 5 ---
464: -- Innerloop iteration 1 of Outerloop iteration 5 --
465: bool(true)
466: bool(true)
467: bool(true)
468: bool(true)
469: object_class::foo1
470: bool(true)
471: object_class::foo1
472: -- Innerloop iteration 2 of Outerloop iteration 5 --
473: bool(false)
474: bool(true)
475: bool(false)
476: bool(true)
477: object_class::foo2
478: bool(false)
479: object_class::foo2
480: -- Innerloop iteration 3 of Outerloop iteration 5 --
481: bool(false)
482: bool(true)
483: bool(false)
484: bool(true)
485: object_class::foo3
486: bool(false)
487: object_class::foo3
488: -- Innerloop iteration 4 of Outerloop iteration 5 --
489: bool(true)
490: bool(true)
491: bool(true)
492: bool(true)
493: object_class::x123
494: bool(true)
495: object_class::x123
496: -- Innerloop iteration 5 of Outerloop iteration 5 --
497: bool(true)
498: bool(true)
499: bool(true)
500: bool(true)
501: object_class::null
502: bool(true)
503: object_class::null
504: -- Innerloop iteration 6 of Outerloop iteration 5 --
505: bool(true)
506: bool(true)
507: bool(true)
508: bool(true)
509: object_class::TRUE
510: bool(true)
511: object_class::TRUE
512: -- Innerloop iteration 7 of Outerloop iteration 5 --
513: bool(false)
514: bool(true)
515: bool(false)
516: bool(true)
517: object_class::123
518: bool(false)
519: object_class::123
520: -- Innerloop iteration 8 of Outerloop iteration 5 --
521: bool(false)
522: bool(false)
523: bool(false)
524: bool(false)
525: Array
526: bool(false)
527: Array
528: -- Innerloop iteration 9 of Outerloop iteration 5 --
529: bool(false)
530: bool(true)
531: bool(false)
532: bool(true)
533: object_class::func
534: bool(false)
535: object_class::func
536: -- Innerloop iteration 10 of Outerloop iteration 5 --
537: bool(true)
538: bool(true)
539: bool(true)
540: bool(true)
541: object_class::foo1
542: bool(true)
543: object_class::foo1
544: --- Outerloop iteration 6 ---
545: -- Innerloop iteration 1 of Outerloop iteration 6 --
546: bool(false)
547: bool(true)
548: bool(false)
549: bool(true)
550: no_member_class::foo1
551: bool(false)
552: no_member_class::foo1
553: -- Innerloop iteration 2 of Outerloop iteration 6 --
554: bool(false)
555: bool(true)
556: bool(false)
557: bool(true)
558: no_member_class::foo2
559: bool(false)
560: no_member_class::foo2
561: -- Innerloop iteration 3 of Outerloop iteration 6 --
562: bool(false)
563: bool(true)
564: bool(false)
565: bool(true)
566: no_member_class::foo3
567: bool(false)
568: no_member_class::foo3
569: -- Innerloop iteration 4 of Outerloop iteration 6 --
570: bool(false)
571: bool(true)
572: bool(false)
573: bool(true)
574: no_member_class::x123
575: bool(false)
576: no_member_class::x123
577: -- Innerloop iteration 5 of Outerloop iteration 6 --
578: bool(false)
579: bool(true)
580: bool(false)
581: bool(true)
582: no_member_class::null
583: bool(false)
584: no_member_class::null
585: -- Innerloop iteration 6 of Outerloop iteration 6 --
586: bool(false)
587: bool(true)
588: bool(false)
589: bool(true)
590: no_member_class::TRUE
591: bool(false)
592: no_member_class::TRUE
593: -- Innerloop iteration 7 of Outerloop iteration 6 --
594: bool(false)
595: bool(true)
596: bool(false)
597: bool(true)
598: no_member_class::123
599: bool(false)
600: no_member_class::123
601: -- Innerloop iteration 8 of Outerloop iteration 6 --
602: bool(false)
603: bool(false)
604: bool(false)
605: bool(false)
606: Array
607: bool(false)
608: Array
609: -- Innerloop iteration 9 of Outerloop iteration 6 --
610: bool(false)
611: bool(true)
612: bool(false)
613: bool(true)
614: no_member_class::func
615: bool(false)
616: no_member_class::func
617: -- Innerloop iteration 10 of Outerloop iteration 6 --
618: bool(true)
619: bool(true)
620: bool(true)
621: bool(true)
622: object_class::foo1
623: bool(true)
624: object_class::foo1
625: --- Outerloop iteration 7 ---
626: -- Innerloop iteration 1 of Outerloop iteration 7 --
627: bool(true)
628: bool(true)
629: bool(true)
630: bool(true)
631: object_class::foo1
632: bool(true)
633: object_class::foo1
634: -- Innerloop iteration 2 of Outerloop iteration 7 --
635: bool(false)
636: bool(true)
637: bool(false)
638: bool(true)
639: object_class::foo2
640: bool(false)
641: object_class::foo2
642: -- Innerloop iteration 3 of Outerloop iteration 7 --
643: bool(false)
644: bool(true)
645: bool(false)
646: bool(true)
647: object_class::foo3
648: bool(false)
649: object_class::foo3
650: -- Innerloop iteration 4 of Outerloop iteration 7 --
651: bool(true)
652: bool(true)
653: bool(true)
654: bool(true)
655: object_class::x123
656: bool(true)
657: object_class::x123
658: -- Innerloop iteration 5 of Outerloop iteration 7 --
659: bool(true)
660: bool(true)
661: bool(true)
662: bool(true)
663: object_class::null
664: bool(true)
665: object_class::null
666: -- Innerloop iteration 6 of Outerloop iteration 7 --
667: bool(true)
668: bool(true)
669: bool(true)
670: bool(true)
671: object_class::TRUE
672: bool(true)
673: object_class::TRUE
674: -- Innerloop iteration 7 of Outerloop iteration 7 --
675: bool(false)
676: bool(true)
677: bool(false)
678: bool(true)
679: object_class::123
680: bool(false)
681: object_class::123
682: -- Innerloop iteration 8 of Outerloop iteration 7 --
683: bool(false)
684: bool(false)
685: bool(false)
686: bool(false)
687: Array
688: bool(false)
689: Array
690: -- Innerloop iteration 9 of Outerloop iteration 7 --
691: bool(false)
692: bool(true)
693: bool(false)
694: bool(true)
695: object_class::func
696: bool(false)
697: object_class::func
698: -- Innerloop iteration 10 of Outerloop iteration 7 --
699: bool(true)
700: bool(true)
701: bool(true)
702: bool(true)
703: object_class::foo1
704: bool(true)
705: object_class::foo1
706: --- Outerloop iteration 8 ---
707: -- Innerloop iteration 1 of Outerloop iteration 8 --
708: bool(false)
709: bool(false)
710: bool(false)
711: bool(false)
712: Array
713: bool(false)
714: Array
715: -- Innerloop iteration 2 of Outerloop iteration 8 --
716: bool(false)
717: bool(false)
718: bool(false)
719: bool(false)
720: Array
721: bool(false)
722: Array
723: -- Innerloop iteration 3 of Outerloop iteration 8 --
724: bool(false)
725: bool(false)
726: bool(false)
727: bool(false)
728: Array
729: bool(false)
730: Array
731: -- Innerloop iteration 4 of Outerloop iteration 8 --
732: bool(false)
733: bool(false)
734: bool(false)
735: bool(false)
736: Array
737: bool(false)
738: Array
739: -- Innerloop iteration 5 of Outerloop iteration 8 --
740: bool(false)
741: bool(false)
742: bool(false)
743: bool(false)
744: Array
745: bool(false)
746: Array
747: -- Innerloop iteration 6 of Outerloop iteration 8 --
748: bool(false)
749: bool(false)
750: bool(false)
751: bool(false)
752: Array
753: bool(false)
754: Array
755: -- Innerloop iteration 7 of Outerloop iteration 8 --
756: bool(false)
757: bool(false)
758: bool(false)
759: bool(false)
760: Array
761: bool(false)
762: Array
763: -- Innerloop iteration 8 of Outerloop iteration 8 --
764: bool(false)
765: bool(false)
766: bool(false)
767: bool(false)
768: Array
769: bool(false)
770: Array
771: -- Innerloop iteration 9 of Outerloop iteration 8 --
772: bool(false)
773: bool(false)
774: bool(false)
775: bool(false)
776: Array
777: bool(false)
778: Array
779: -- Innerloop iteration 10 of Outerloop iteration 8 --
780: bool(true)
781: bool(true)
782: bool(true)
783: bool(true)
784: object_class::foo1
785: bool(true)
786: object_class::foo1
787: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>