Annotation of embedaddon/php/ext/standard/tests/general_functions/call_user_func_array_variation_003.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test call_user_func_array() function : second parameter variation 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : mixed call_user_func_array(string function_name, array parameters)
                      6:  * Description: Call a user function which is the first parameter with the arguments contained in array 
                      7:  * Source code: ext/standard/basic_functions.c
                      8:  * Alias to functions: 
                      9:  */
                     10: 
                     11: echo "*** Testing call_user_func_array() : usage variation ***\n";
                     12: 
                     13: // Define error handler
                     14: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
                     15:        if (error_reporting() != 0) {
                     16:                // report non-silenced errors
                     17:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
                     18:        }
                     19: }
                     20: set_error_handler('test_error_handler');
                     21: 
                     22: // Initialise function arguments not being substituted (if any)
                     23: function test_func() {
                     24: }
                     25: $function_name = 'test_func';
                     26: 
                     27: //get an unset variable
                     28: $unset_var = 10;
                     29: unset ($unset_var);
                     30: 
                     31: // define some classes
                     32: class classWithToString
                     33: {
                     34:        public function __toString() {
                     35:                return "Class A object";
                     36:        }
                     37: }
                     38: 
                     39: class classWithoutToString
                     40: {
                     41: }
                     42: 
                     43: // heredoc string
                     44: $heredoc = <<<EOT
                     45: hello world
                     46: EOT;
                     47: 
                     48: // add arrays
                     49: $index_array = array (1, 2, 3);
                     50: $assoc_array = array ('one' => 1, 'two' => 2);
                     51: 
                     52: //array of values to iterate over
                     53: $inputs = array(
                     54: 
                     55:       // int data
                     56:       'int 0' => 0,
                     57:       'int 1' => 1,
                     58:       'int 12345' => 12345,
                     59:       'int -12345' => -2345,
                     60: 
                     61:       // float data
                     62:       'float 10.5' => 10.5,
                     63:       'float -10.5' => -10.5,
                     64:       'float 12.3456789000e10' => 12.3456789000e10,
                     65:       'float -12.3456789000e10' => -12.3456789000e10,
                     66:       'float .5' => .5,
                     67: 
                     68:       // null data
                     69:       'uppercase NULL' => NULL,
                     70:       'lowercase null' => null,
                     71: 
                     72:       // boolean data
                     73:       'lowercase true' => true,
                     74:       'lowercase false' =>false,
                     75:       'uppercase TRUE' =>TRUE,
                     76:       'uppercase FALSE' =>FALSE,
                     77: 
                     78:       // empty data
                     79:       'empty string DQ' => "",
                     80:       'empty string SQ' => '',
                     81: 
                     82:       // string data
                     83:       'string DQ' => "string",
                     84:       'string SQ' => 'string',
                     85:       'mixed case string' => "sTrInG",
                     86:       'heredoc' => $heredoc,
                     87: 
                     88:       // object data
                     89:       'instance of classWithToString' => new classWithToString(),
                     90:       'instance of classWithoutToString' => new classWithoutToString(),
                     91: 
                     92:       // undefined data
                     93:       'undefined var' => @$undefined_var,
                     94: 
                     95:       // unset data
                     96:       'unset var' => @$unset_var,
                     97: );
                     98: 
                     99: // loop through each element of the array for parameters
                    100: 
                    101: foreach($inputs as $key =>$value) {
                    102:       echo "\n--$key--\n";
                    103:       var_dump( call_user_func_array($function_name, $value) );
                    104: };
                    105: 
                    106: ?>
                    107: ===DONE===
                    108: --EXPECTF--
                    109: *** Testing call_user_func_array() : usage variation ***
                    110: 
                    111: --int 0--
                    112: Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
                    113: NULL
                    114: 
                    115: --int 1--
                    116: Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
                    117: NULL
                    118: 
                    119: --int 12345--
                    120: Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
                    121: NULL
                    122: 
                    123: --int -12345--
                    124: Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
                    125: NULL
                    126: 
                    127: --float 10.5--
                    128: Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
                    129: NULL
                    130: 
                    131: --float -10.5--
                    132: Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
                    133: NULL
                    134: 
                    135: --float 12.3456789000e10--
                    136: Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
                    137: NULL
                    138: 
                    139: --float -12.3456789000e10--
                    140: Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
                    141: NULL
                    142: 
                    143: --float .5--
                    144: Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
                    145: NULL
                    146: 
                    147: --uppercase NULL--
                    148: Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
                    149: NULL
                    150: 
                    151: --lowercase null--
                    152: Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
                    153: NULL
                    154: 
                    155: --lowercase true--
                    156: Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
                    157: NULL
                    158: 
                    159: --lowercase false--
                    160: Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
                    161: NULL
                    162: 
                    163: --uppercase TRUE--
                    164: Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
                    165: NULL
                    166: 
                    167: --uppercase FALSE--
                    168: Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
                    169: NULL
                    170: 
                    171: --empty string DQ--
                    172: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    173: NULL
                    174: 
                    175: --empty string SQ--
                    176: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    177: NULL
                    178: 
                    179: --string DQ--
                    180: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    181: NULL
                    182: 
                    183: --string SQ--
                    184: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    185: NULL
                    186: 
                    187: --mixed case string--
                    188: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    189: NULL
                    190: 
                    191: --heredoc--
                    192: Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
                    193: NULL
                    194: 
                    195: --instance of classWithToString--
                    196: Error: 2 - call_user_func_array() expects parameter 2 to be array, object given, %s(%d)
                    197: NULL
                    198: 
                    199: --instance of classWithoutToString--
                    200: Error: 2 - call_user_func_array() expects parameter 2 to be array, object given, %s(%d)
                    201: NULL
                    202: 
                    203: --undefined var--
                    204: Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
                    205: NULL
                    206: 
                    207: --unset var--
                    208: Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
                    209: NULL
                    210: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>