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

1.1       misho       1: --TEST--
                      2: Test strrpos() function : usage variations - unexpected inputs for 'needle' argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : int strrpos ( string $haystack, string $needle [, int $offset] );
                      6:  * Description: Find position of last occurrence of 'needle' in 'haystack'.
                      7:  * Source code: ext/standard/string.c
                      8: */
                      9: 
                     10: /* Test strrpos() function with unexpected inputs for 'needle' and 
                     11:  *  an expected type of input for 'haystack' argument 
                     12: */
                     13: 
                     14: echo "*** Testing strrpos() function with unexpected values for needle ***\n";
                     15: 
                     16: //get an unset variable
                     17: $unset_var = 'string_val';
                     18: unset($unset_var);
                     19: 
                     20: //defining a class
                     21: class sample  {
                     22:   public function __toString() {
                     23:     return "object";
                     24:   } 
                     25: }
                     26: 
                     27: //getting the resource
                     28: $file_handle = fopen(__FILE__, "r");
                     29: 
                     30: $haystack = "string 0 1 2 -2 10.5 -10.5 10.5e10 10.6E-10 .5 array true false object \"\" null Resource";
                     31: 
                     32: // array with different values
                     33: $needles =  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', 'item' => 'pen'),
                     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:   // resource
                     73:   $file_handle,
                     74: 
                     75:   // undefined variable
                     76:   @$undefined_var,
                     77: 
                     78:   // unset variable
                     79:   @$unset_var
                     80: );
                     81: 
                     82: // loop through each element of the 'needle' array to check the working of strrpos()
                     83: $counter = 1;
                     84: for($index = 0; $index < count($needles); $index ++) {
                     85:   echo "-- Iteration $counter --\n";
                     86:   var_dump( strrpos($haystack, $needles[$index]) );
                     87:   $counter ++;
                     88: }
                     89: 
                     90: fclose($file_handle);  //closing the file handle
                     91: 
                     92: echo "*** Done ***";
                     93: ?>
                     94: --EXPECTF--
                     95: *** Testing strrpos() function with unexpected values for needle ***
                     96: -- Iteration 1 --
                     97: bool(false)
                     98: -- Iteration 2 --
                     99: bool(false)
                    100: -- Iteration 3 --
                    101: bool(false)
                    102: -- Iteration 4 --
                    103: bool(false)
                    104: -- Iteration 5 --
                    105: bool(false)
                    106: -- Iteration 6 --
                    107: bool(false)
                    108: -- Iteration 7 --
                    109: bool(false)
                    110: -- Iteration 8 --
                    111: bool(false)
                    112: -- Iteration 9 --
                    113: bool(false)
                    114: -- Iteration 10 --
                    115: 
                    116: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    117: bool(false)
                    118: -- Iteration 11 --
                    119: 
                    120: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    121: bool(false)
                    122: -- Iteration 12 --
                    123: 
                    124: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    125: bool(false)
                    126: -- Iteration 13 --
                    127: 
                    128: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    129: bool(false)
                    130: -- Iteration 14 --
                    131: 
                    132: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    133: bool(false)
                    134: -- Iteration 15 --
                    135: bool(false)
                    136: -- Iteration 16 --
                    137: bool(false)
                    138: -- Iteration 17 --
                    139: bool(false)
                    140: -- Iteration 18 --
                    141: bool(false)
                    142: -- Iteration 19 --
                    143: 
                    144: Notice: Object of class sample could not be converted to int in %s on line %d
                    145: bool(false)
                    146: -- Iteration 20 --
                    147: bool(false)
                    148: -- Iteration 21 --
                    149: bool(false)
                    150: -- Iteration 22 --
                    151: bool(false)
                    152: -- Iteration 23 --
                    153: bool(false)
                    154: -- Iteration 24 --
                    155: 
                    156: Warning: strrpos(): needle is not a string or an integer in %s on line %d
                    157: bool(false)
                    158: -- Iteration 25 --
                    159: bool(false)
                    160: -- Iteration 26 --
                    161: bool(false)
                    162: *** Done ***

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