Annotation of embedaddon/php/ext/standard/tests/general_functions/is_callable_basic1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test is_callable() function : usage variations - defined functions
! 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: * Source code: ext/imap/php_imap.c
! 11: */
! 12:
! 13: /* Prototype: void check_iscallable( $functions );
! 14: Description: use iscallable() on given string to check for valid function name
! 15: returns true if valid function name, false otherwise
! 16: */
! 17: function check_iscallable( $functions ) {
! 18: $counter = 1;
! 19: foreach($functions as $func) {
! 20: echo "-- Iteration $counter --\n";
! 21: var_dump( is_callable($func) ); //given only $var argument
! 22: var_dump( is_callable($func, TRUE) ); //given $var and $syntax argument
! 23: var_dump( is_callable($func, TRUE, $callable_name) );
! 24: echo $callable_name, "\n";
! 25: var_dump( is_callable($func, FALSE) ); //given $var and $syntax argument
! 26: var_dump( is_callable($func, FALSE, $callable_name) );
! 27: echo $callable_name, "\n";
! 28: $counter++;
! 29: }
! 30: }
! 31:
! 32: echo "\n*** Testing is_callable() on defined functions ***\n";
! 33: /* function name with simple string */
! 34: function someFunction() {
! 35: }
! 36:
! 37: /* function name with mixed string and integer */
! 38: function x123() {
! 39: }
! 40:
! 41: /* function name as NULL */
! 42: function NULL() {
! 43: }
! 44:
! 45: /* function name with boolean name */
! 46: function false() {
! 47: }
! 48:
! 49: /* function name with string and special character */
! 50: function Hello_World() {
! 51: }
! 52:
! 53: $defined_functions = array (
! 54: $functionVar1 = 'someFunction',
! 55: $functionVar2 = 'x123',
! 56: $functionVar3 = 'NULL',
! 57: $functionVar4 = 'false',
! 58: $functionVar5 = "Hello_World"
! 59: );
! 60: /* use check_iscallable() to check whether given string is valid function name
! 61: * expected: true as it is valid callback
! 62: */
! 63: check_iscallable($defined_functions);
! 64:
! 65: ?>
! 66: ===DONE===
! 67: --EXPECT--
! 68: *** Testing is_callable() on defined functions ***
! 69: -- Iteration 1 --
! 70: bool(true)
! 71: bool(true)
! 72: bool(true)
! 73: someFunction
! 74: bool(true)
! 75: bool(true)
! 76: someFunction
! 77: -- Iteration 2 --
! 78: bool(true)
! 79: bool(true)
! 80: bool(true)
! 81: x123
! 82: bool(true)
! 83: bool(true)
! 84: x123
! 85: -- Iteration 3 --
! 86: bool(true)
! 87: bool(true)
! 88: bool(true)
! 89: NULL
! 90: bool(true)
! 91: bool(true)
! 92: NULL
! 93: -- Iteration 4 --
! 94: bool(true)
! 95: bool(true)
! 96: bool(true)
! 97: false
! 98: bool(true)
! 99: bool(true)
! 100: false
! 101: -- Iteration 5 --
! 102: bool(true)
! 103: bool(true)
! 104: bool(true)
! 105: Hello_World
! 106: bool(true)
! 107: bool(true)
! 108: Hello_World
! 109: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>