Annotation of embedaddon/php/ext/standard/tests/strings/stripos_variation9.phpt, revision 1.1.1.1

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

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