Return to strrpos_variation9.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strrpos() function : usage variations - unexpected inputs for 'haystack' 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 haystack argument */ 11: 12: echo "*** Testing strrpos() 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 strrpos() 81: $counter = 1; 82: for($index = 0; $index < count($haystacks); $index ++) { 83: echo "\n-- Iteration $counter --\n"; 84: var_dump( strrpos($haystacks[$index], $needle) ); 85: $counter ++; 86: } 87: 88: fclose($file_handle); //closing the file handle 89: 90: echo "*** Done ***"; 91: ?> 92: --EXPECTF-- 93: *** Testing strrpos() 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: strrpos() expects parameter 1 to be string, array given in %s on line %d 125: bool(false) 126: 127: -- Iteration 11 -- 128: 129: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d 130: bool(false) 131: 132: -- Iteration 12 -- 133: 134: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d 135: bool(false) 136: 137: -- Iteration 13 -- 138: 139: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d 140: bool(false) 141: 142: -- Iteration 14 -- 143: 144: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d 145: bool(false) 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: strrpos() expects parameter 1 to be string, resource given in %s on line %d 177: bool(false) 178: 179: -- Iteration 25 -- 180: bool(false) 181: 182: -- Iteration 26 -- 183: bool(false) 184: *** Done ***