Annotation of embedaddon/php/ext/standard/tests/strings/strtok_variation1.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test strtok() function : usage variations - first argument as non-string
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : string strtok ( string $str, string $token )
                      6:  * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
                      7:  * Source code: ext/standard/string.c
                      8: */
                      9: 
                     10: /*
                     11:  * Testing strtok() : with first argument as non-string
                     12: */
                     13: 
                     14: echo "*** Testing strtok() : with first argument as non-string ***\n";
                     15: // initialize all required variables
                     16: $token = '-';
                     17: 
                     18: // get an unset variable
                     19: $unset_var = 'string_val';
                     20: unset($unset_var);
                     21: 
                     22: // declaring a class
                     23: class sample  {
                     24:   public function __toString() {
                     25:   return "obj-ect";
                     26:   }
                     27: }
                     28: 
                     29: // Defining resource
                     30: $file_handle = fopen(__FILE__, 'r');
                     31: 
                     32: // array with different values
                     33: $values =  array (
                     34: 
                     35:   // integer values
                     36:   0,
                     37:   1,
                     38:   12345,
                     39:   -2345,
                     40: 
                     41:   // float values
                     42:   10.5,
                     43:   -10.5,
                     44:   10.1234567e10,
                     45:   10.7654321E-10,
                     46:   .5,
                     47: 
                     48:   // array values
                     49:   array(),
                     50:   array(0),
                     51:   array(1),
                     52:   array(1, 2),
                     53:   array('color' => 'red-color', 'item' => 'pen-color'),
                     54: 
                     55:   // boolean values
                     56:   true,
                     57:   false,
                     58:   TRUE,
                     59:   FALSE,
                     60: 
                     61:   // objects
                     62:   new sample(),
                     63: 
                     64:   // empty string
                     65:   "",
                     66:   '',
                     67: 
                     68:   // null vlaues
                     69:   NULL,
                     70:   null,
                     71: 
                     72:   // undefined variable
                     73:   $undefined_var,
                     74: 
                     75:   // unset variable
                     76:   $unset_var,
                     77: 
                     78:   // resource
                     79:   $file_handle
                     80: );
                     81: 
                     82: 
                     83: // loop through each element of the array and check the working of strtok()
1.1.1.2 ! misho      84: // when $str argument is supplied with different values
1.1       misho      85: 
                     86: echo "\n--- Testing strtok() by supplying different values for 'str' argument ---\n";
                     87: $counter = 1;
                     88: for($index = 0; $index < count($values); $index ++) {
                     89:   echo "-- Iteration $counter --\n";
                     90:   $str = $values [$index];
                     91: 
                     92:   var_dump( strtok($str, $token) );
                     93: 
                     94:   $counter ++;
                     95: }
                     96: 
                     97: //closing the resource 
                     98: fclose($file_handle);
                     99: 
                    100: echo "Done\n";
                    101: ?>
                    102: --EXPECTF--
                    103: *** Testing strtok() : with first argument as non-string ***
                    104: 
                    105: Notice: Undefined variable: undefined_var in %s on line %d
                    106: 
                    107: Notice: Undefined variable: unset_var in %s on line %d
                    108: 
                    109: --- Testing strtok() by supplying different values for 'str' argument ---
                    110: -- Iteration 1 --
                    111: string(1) "0"
                    112: -- Iteration 2 --
                    113: string(1) "1"
                    114: -- Iteration 3 --
                    115: string(5) "12345"
                    116: -- Iteration 4 --
                    117: string(4) "2345"
                    118: -- Iteration 5 --
                    119: string(4) "10.5"
                    120: -- Iteration 6 --
                    121: string(4) "10.5"
                    122: -- Iteration 7 --
                    123: string(12) "101234567000"
                    124: -- Iteration 8 --
                    125: string(11) "1.07654321E"
                    126: -- Iteration 9 --
                    127: string(3) "0.5"
                    128: -- Iteration 10 --
                    129: 
                    130: Warning: strtok() expects parameter 1 to be string, array given in %s on line %d
                    131: NULL
                    132: -- Iteration 11 --
                    133: 
                    134: Warning: strtok() expects parameter 1 to be string, array given in %s on line %d
                    135: NULL
                    136: -- Iteration 12 --
                    137: 
                    138: Warning: strtok() expects parameter 1 to be string, array given in %s on line %d
                    139: NULL
                    140: -- Iteration 13 --
                    141: 
                    142: Warning: strtok() expects parameter 1 to be string, array given in %s on line %d
                    143: NULL
                    144: -- Iteration 14 --
                    145: 
                    146: Warning: strtok() expects parameter 1 to be string, array given in %s on line %d
                    147: NULL
                    148: -- Iteration 15 --
                    149: string(1) "1"
                    150: -- Iteration 16 --
                    151: bool(false)
                    152: -- Iteration 17 --
                    153: string(1) "1"
                    154: -- Iteration 18 --
                    155: bool(false)
                    156: -- Iteration 19 --
                    157: string(3) "obj"
                    158: -- Iteration 20 --
                    159: bool(false)
                    160: -- Iteration 21 --
                    161: bool(false)
                    162: -- Iteration 22 --
                    163: bool(false)
                    164: -- Iteration 23 --
                    165: bool(false)
                    166: -- Iteration 24 --
                    167: bool(false)
                    168: -- Iteration 25 --
                    169: bool(false)
                    170: -- Iteration 26 --
                    171: 
                    172: Warning: strtok() expects parameter 1 to be string, resource given in %s on line %d
                    173: NULL
                    174: Done

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