mirror of
https://github.com/php/php-src.git
synced 2024-09-27 04:47:22 +00:00
New testcases for strrpos() function
This commit is contained in:
parent
0513f160c9
commit
703626aa98
66
ext/standard/tests/strings/strrpos_basic1.phpt
Normal file
66
ext/standard/tests/strings/strrpos_basic1.phpt
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : basic functionality - with default arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: basic functionality ***\n";
|
||||||
|
$heredoc_str = <<<EOD
|
||||||
|
Hello, World
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
echo "-- With default arguments --\n";
|
||||||
|
//regular string for haystack & needle
|
||||||
|
var_dump( strrpos("Hello, World", "Hello") );
|
||||||
|
var_dump( strrpos('Hello, World', "hello") );
|
||||||
|
var_dump( strrpos("Hello, World", 'World') );
|
||||||
|
var_dump( strrpos('Hello, World', 'WORLD') );
|
||||||
|
|
||||||
|
//single char for needle
|
||||||
|
var_dump( strrpos("Hello, World", "o") );
|
||||||
|
var_dump( strrpos("Hello, World", ",") );
|
||||||
|
|
||||||
|
//heredoc string for haystack & needle
|
||||||
|
var_dump( strrpos($heredoc_str, "Hello, World") );
|
||||||
|
var_dump( strrpos($heredoc_str, 'Hello') );
|
||||||
|
var_dump( strrpos($heredoc_str, $heredoc_str) );
|
||||||
|
|
||||||
|
//unicodes
|
||||||
|
var_dump( strrpos("Hello, World", (unicode)"o") );
|
||||||
|
var_dump( strrpos((unicode)"Hello, World", ",") );
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: basic functionality ***
|
||||||
|
-- With default arguments --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(7)
|
||||||
|
bool(false)
|
||||||
|
int(8)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
int(8)
|
||||||
|
int(5)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: basic functionality ***
|
||||||
|
-- With default arguments --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(7)
|
||||||
|
bool(false)
|
||||||
|
int(8)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
int(8)
|
||||||
|
int(5)
|
||||||
|
*** Done ***
|
71
ext/standard/tests/strings/strrpos_basic2.phpt
Normal file
71
ext/standard/tests/strings/strrpos_basic2.phpt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : basic functionality - with all arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: basic functionality ***\n";
|
||||||
|
$heredoc_str = <<<EOD
|
||||||
|
Hello, World
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
echo "-- With all arguments --\n";
|
||||||
|
//regular string for haystack & needle, with various offsets
|
||||||
|
var_dump( strrpos("Hello, World", "Hello", 0) );
|
||||||
|
var_dump( strrpos("Hello, World", 'Hello', 1) );
|
||||||
|
var_dump( strrpos('Hello, World', 'World', 1) );
|
||||||
|
var_dump( strrpos('Hello, World', "World", 5) );
|
||||||
|
|
||||||
|
//heredoc string for haystack & needle, with various offsets
|
||||||
|
var_dump( strrpos($heredoc_str, "Hello, World", 0) );
|
||||||
|
var_dump( strrpos($heredoc_str, 'Hello', 0) );
|
||||||
|
var_dump( strrpos($heredoc_str, 'Hello', 1) );
|
||||||
|
var_dump( strrpos($heredoc_str, $heredoc_str, 0) );
|
||||||
|
var_dump( strrpos($heredoc_str, $heredoc_str, 1) );
|
||||||
|
|
||||||
|
//various offsets
|
||||||
|
var_dump( strrpos("Hello, World", "o", 3) );
|
||||||
|
var_dump( strrpos("Hello, World", "o", 6) );
|
||||||
|
var_dump( strrpos("Hello, World", "o", 10) );
|
||||||
|
var_dump( strrpos("Hello, World", "Hello, world", -2) );
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: basic functionality ***
|
||||||
|
-- With all arguments --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(7)
|
||||||
|
int(7)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(8)
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: basic functionality ***
|
||||||
|
-- With all arguments --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(7)
|
||||||
|
int(7)
|
||||||
|
int(0)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(0)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
int(8)
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
48
ext/standard/tests/strings/strrpos_error.phpt
Normal file
48
ext/standard/tests/strings/strrpos_error.phpt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : error conditions
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: error conditions ***";
|
||||||
|
echo "\n-- With Zero arguments --";
|
||||||
|
var_dump( strrpos() );
|
||||||
|
|
||||||
|
echo "\n-- With less than expected number of arguments --";
|
||||||
|
var_dump( strrpos("String") );
|
||||||
|
|
||||||
|
echo "\n-- With more than expected number of arguments --";
|
||||||
|
var_dump( strrpos("string", "String", 1, 'extra_arg') );
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: error conditions ***
|
||||||
|
-- With Zero arguments --
|
||||||
|
Warning: strrpos() expects at least 2 parameters, 0 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- With less than expected number of arguments --
|
||||||
|
Warning: strrpos() expects at least 2 parameters, 1 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- With more than expected number of arguments --
|
||||||
|
Warning: strrpos() expects at most 3 parameters, 4 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: error conditions ***
|
||||||
|
-- With Zero arguments --
|
||||||
|
Warning: strrpos() expects at least 2 parameters, 0 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- With less than expected number of arguments --
|
||||||
|
Warning: strrpos() expects at least 2 parameters, 1 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- With more than expected number of arguments --
|
||||||
|
Warning: strrpos() expects at most 3 parameters, 4 given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
292
ext/standard/tests/strings/strrpos_variation1.phpt
Normal file
292
ext/standard/tests/strings/strrpos_variation1.phpt
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - double quoted strings for 'haystack' & 'needle' arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing double quoted strings for 'haystack' & 'needle' arguments */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with double quoted strings ***\n";
|
||||||
|
$haystack = "Hello,\t\n\0\n $&!#%()*<=>?@hello123456he \x234 \101 ";
|
||||||
|
$needle = array(
|
||||||
|
//regular strings
|
||||||
|
"l",
|
||||||
|
"L",
|
||||||
|
"HELLO",
|
||||||
|
"hEllo",
|
||||||
|
|
||||||
|
//escape characters
|
||||||
|
"\t",
|
||||||
|
"\T", //invalid input
|
||||||
|
" ",
|
||||||
|
"\n",
|
||||||
|
"\N", //invalid input
|
||||||
|
"
|
||||||
|
", //new line
|
||||||
|
|
||||||
|
//nulls
|
||||||
|
"\0",
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
//boolean false
|
||||||
|
FALSE,
|
||||||
|
false,
|
||||||
|
|
||||||
|
//empty string
|
||||||
|
"",
|
||||||
|
|
||||||
|
//special chars
|
||||||
|
" ",
|
||||||
|
"$",
|
||||||
|
" $",
|
||||||
|
"&",
|
||||||
|
"!#",
|
||||||
|
"()",
|
||||||
|
"<=>",
|
||||||
|
">",
|
||||||
|
"=>",
|
||||||
|
"?",
|
||||||
|
"@",
|
||||||
|
"@hEllo",
|
||||||
|
|
||||||
|
"12345", //decimal numeric string
|
||||||
|
"\x23", //hexadecimal numeric string
|
||||||
|
"#", //respective ASCII char of \x23
|
||||||
|
"\101", //octal numeric string
|
||||||
|
"A", //respective ASCII char of \101
|
||||||
|
"456HEE", //numerics + chars
|
||||||
|
$haystack //haystack as needle
|
||||||
|
);
|
||||||
|
|
||||||
|
/* loop through to get the position of the needle in haystack string */
|
||||||
|
$count = 1;
|
||||||
|
for($index=0; $index<count($needle); $index++) {
|
||||||
|
echo "-- Iteration $count --\n";
|
||||||
|
var_dump( strrpos($haystack, $needle[$index]) );
|
||||||
|
var_dump( strrpos($haystack, $needle[$index], $index) );
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with double quoted strings ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(28)
|
||||||
|
int(28)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
int(9)
|
||||||
|
int(9)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
int(9)
|
||||||
|
int(9)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
int(43)
|
||||||
|
int(43)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(12)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(11)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
int(13)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(14)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(17)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
int(20)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
int(22)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
int(21)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
int(23)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 27 --
|
||||||
|
int(24)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 28 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 29 --
|
||||||
|
int(30)
|
||||||
|
int(30)
|
||||||
|
-- Iteration 30 --
|
||||||
|
int(39)
|
||||||
|
int(39)
|
||||||
|
-- Iteration 31 --
|
||||||
|
int(39)
|
||||||
|
int(39)
|
||||||
|
-- Iteration 32 --
|
||||||
|
int(42)
|
||||||
|
int(42)
|
||||||
|
-- Iteration 33 --
|
||||||
|
int(42)
|
||||||
|
int(42)
|
||||||
|
-- Iteration 34 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 35 --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with double quoted strings ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(28)
|
||||||
|
int(28)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
int(9)
|
||||||
|
int(9)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
int(9)
|
||||||
|
int(9)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
int(8)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
int(43)
|
||||||
|
int(43)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(12)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(11)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
int(13)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(14)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(17)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
int(20)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
int(22)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
int(21)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
int(23)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 27 --
|
||||||
|
int(24)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 28 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 29 --
|
||||||
|
int(30)
|
||||||
|
int(30)
|
||||||
|
-- Iteration 30 --
|
||||||
|
int(39)
|
||||||
|
int(39)
|
||||||
|
-- Iteration 31 --
|
||||||
|
int(39)
|
||||||
|
int(39)
|
||||||
|
-- Iteration 32 --
|
||||||
|
int(42)
|
||||||
|
int(42)
|
||||||
|
-- Iteration 33 --
|
||||||
|
int(42)
|
||||||
|
int(42)
|
||||||
|
-- Iteration 34 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 35 --
|
||||||
|
int(0)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
213
ext/standard/tests/strings/strrpos_variation10.phpt
Normal file
213
ext/standard/tests/strings/strrpos_variation10.phpt
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - unexpected inputs for 'needle' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with unexpected inputs for 'needle' and
|
||||||
|
* an expected type of input for 'haystack' argument
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function with unexpected values for needle ***\n";
|
||||||
|
|
||||||
|
//get an unset variable
|
||||||
|
$unset_var = 'string_val';
|
||||||
|
unset($unset_var);
|
||||||
|
|
||||||
|
//defining a class
|
||||||
|
class sample {
|
||||||
|
public function __toString() {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//getting the resource
|
||||||
|
$file_handle = fopen(__FILE__, "r");
|
||||||
|
|
||||||
|
$haystack = "string 0 1 2 -2 10.5 -10.5 10.5e10 10.6E-10 .5 array true false object \"\" null Resource";
|
||||||
|
|
||||||
|
// array with different values
|
||||||
|
$needles = array (
|
||||||
|
|
||||||
|
// integer values
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
12345,
|
||||||
|
-2345,
|
||||||
|
|
||||||
|
// float values
|
||||||
|
10.5,
|
||||||
|
-10.5,
|
||||||
|
10.5e10,
|
||||||
|
10.6E-10,
|
||||||
|
.5,
|
||||||
|
|
||||||
|
// array values
|
||||||
|
array(),
|
||||||
|
array(0),
|
||||||
|
array(1),
|
||||||
|
array(1, 2),
|
||||||
|
array('color' => 'red', 'item' => 'pen'),
|
||||||
|
|
||||||
|
// boolean values
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
// objects
|
||||||
|
new sample(),
|
||||||
|
|
||||||
|
// empty string
|
||||||
|
"",
|
||||||
|
'',
|
||||||
|
|
||||||
|
// null vlaues
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
// resource
|
||||||
|
$file_handle,
|
||||||
|
|
||||||
|
// undefined variable
|
||||||
|
@$undefined_var,
|
||||||
|
|
||||||
|
// unset variable
|
||||||
|
@$unset_var
|
||||||
|
);
|
||||||
|
|
||||||
|
// loop through each element of the 'needle' array to check the working of strrpos()
|
||||||
|
$counter = 1;
|
||||||
|
for($index = 0; $index < count($needles); $index ++) {
|
||||||
|
echo "-- Iteration $counter --\n";
|
||||||
|
var_dump( strrpos($haystack, $needles[$index]) );
|
||||||
|
$counter ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($file_handle); //closing the file handle
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for needle ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for needle ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
320
ext/standard/tests/strings/strrpos_variation11.phpt
Normal file
320
ext/standard/tests/strings/strrpos_variation11.phpt
Normal file
@ -0,0 +1,320 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with unexpected inputs for 'haystack' and 'needle' arguments */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function with unexpected values for haystack and needle ***\n";
|
||||||
|
|
||||||
|
// get an unset variable
|
||||||
|
$unset_var = 'string_val';
|
||||||
|
unset($unset_var);
|
||||||
|
|
||||||
|
// defining a class
|
||||||
|
class sample {
|
||||||
|
public function __toString() {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//getting the resource
|
||||||
|
$file_handle = fopen(__FILE__, "r");
|
||||||
|
|
||||||
|
// array with different values
|
||||||
|
$values = array (
|
||||||
|
|
||||||
|
// integer values
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
12345,
|
||||||
|
-2345,
|
||||||
|
|
||||||
|
// float values
|
||||||
|
10.5,
|
||||||
|
-10.5,
|
||||||
|
10.5e10,
|
||||||
|
10.6E-10,
|
||||||
|
.5,
|
||||||
|
|
||||||
|
// array values
|
||||||
|
array(),
|
||||||
|
array(0),
|
||||||
|
array(1),
|
||||||
|
array(1, 2),
|
||||||
|
array('color' => 'red', 'item' => 'pen'),
|
||||||
|
|
||||||
|
// boolean values
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
// objects
|
||||||
|
new sample(),
|
||||||
|
|
||||||
|
// empty string
|
||||||
|
"",
|
||||||
|
'',
|
||||||
|
|
||||||
|
// null vlaues
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
// resource
|
||||||
|
$file_handle,
|
||||||
|
|
||||||
|
// undefined variable
|
||||||
|
@$undefined_var,
|
||||||
|
|
||||||
|
// unset variable
|
||||||
|
@$unset_var
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// loop through each element of the array and check the working of strrpos()
|
||||||
|
$counter = 1;
|
||||||
|
for($index = 0; $index < count($values); $index ++) {
|
||||||
|
echo "-- Iteration $counter --\n";
|
||||||
|
$haystack = $values[$index];
|
||||||
|
var_dump( strrpos($values[$index], $values[$index]) );
|
||||||
|
var_dump( strrpos($values[$index], $values[$index], 1) );
|
||||||
|
$counter ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for haystack and needle ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for haystack and needle ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: Object of class sample could not be converted to int in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
68
ext/standard/tests/strings/strrpos_variation12.phpt
Normal file
68
ext/standard/tests/strings/strrpos_variation12.phpt
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - checking binary safe with 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with null terminated strings for 'haystack' argument
|
||||||
|
* in order to check the binary safe
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Test strrpos() function: binary safe ***\n";
|
||||||
|
$haystacks = array(
|
||||||
|
"Hello".chr(0)."World",
|
||||||
|
chr(0)."Hello World",
|
||||||
|
"Hello World".chr(0),
|
||||||
|
chr(0).chr(0).chr(0),
|
||||||
|
"Hello\0world",
|
||||||
|
"\0Hello",
|
||||||
|
"Hello\0"
|
||||||
|
);
|
||||||
|
|
||||||
|
for($index = 0; $index < count($haystacks); $index++ ) {
|
||||||
|
var_dump( strrpos($haystacks[$index], "\0") );
|
||||||
|
var_dump( strrpos($haystacks[$index], "\0", $index) );
|
||||||
|
}
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Test strrpos() function: binary safe ***
|
||||||
|
int(5)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(11)
|
||||||
|
int(11)
|
||||||
|
int(2)
|
||||||
|
bool(false)
|
||||||
|
int(5)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(5)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Test strrpos() function: binary safe ***
|
||||||
|
int(5)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(11)
|
||||||
|
int(11)
|
||||||
|
int(2)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
int(5)
|
||||||
|
int(5)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(5)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
70
ext/standard/tests/strings/strrpos_variation13.phpt
Normal file
70
ext/standard/tests/strings/strrpos_variation13.phpt
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - checking binary safe with 'needle' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with null terminated strings for 'needle' argument
|
||||||
|
* in order to check binary safe
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Test strrpos() function: binary safe ***\n";
|
||||||
|
$haystack = "\0Hello\0World\0";
|
||||||
|
|
||||||
|
$needles = array(
|
||||||
|
"Hello".chr(0)."World",
|
||||||
|
chr(0)."Hello\0",
|
||||||
|
chr(0),
|
||||||
|
"Hello\0world",
|
||||||
|
"\0Hello\0world\0",
|
||||||
|
"\0Hello",
|
||||||
|
"Hello\0"
|
||||||
|
);
|
||||||
|
|
||||||
|
for($index = 0; $index < count($needles); $index++ ) {
|
||||||
|
var_dump( strrpos($haystack, $needles[$index]) );
|
||||||
|
var_dump( strrpos($haystack, $needles[$index], $index) );
|
||||||
|
}
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Test strrpos() function: binary safe ***
|
||||||
|
int(1)
|
||||||
|
int(1)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(12)
|
||||||
|
int(12)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(1)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Test strrpos() function: binary safe ***
|
||||||
|
int(1)
|
||||||
|
int(1)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(12)
|
||||||
|
int(12)
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(1)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
224
ext/standard/tests/strings/strrpos_variation14.phpt
Normal file
224
ext/standard/tests/strings/strrpos_variation14.phpt
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - unexpected inputs for 'offset' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with unexpected inputs for 'offset' argument */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with unexpected values for offset ***\n";
|
||||||
|
|
||||||
|
// get an unset variable
|
||||||
|
$unset_var = 'string_val';
|
||||||
|
unset($unset_var);
|
||||||
|
|
||||||
|
// defining a class
|
||||||
|
class sample {
|
||||||
|
public function __toString() {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//getting the resource
|
||||||
|
$file_handle = fopen(__FILE__, "r");
|
||||||
|
|
||||||
|
//definition of input args
|
||||||
|
$haystack = "hello world";
|
||||||
|
$needle = "world";
|
||||||
|
|
||||||
|
// array with different values
|
||||||
|
$offsets = array (
|
||||||
|
|
||||||
|
// float values
|
||||||
|
1.5,
|
||||||
|
-100.5,
|
||||||
|
1.5e10,
|
||||||
|
1.6E-10,
|
||||||
|
.5,
|
||||||
|
|
||||||
|
// array values
|
||||||
|
array(),
|
||||||
|
array(0),
|
||||||
|
array(1),
|
||||||
|
array(1, 2),
|
||||||
|
array('color' => 'red', 'item' => 'pen'),
|
||||||
|
|
||||||
|
// boolean values
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
// objects
|
||||||
|
new sample(),
|
||||||
|
|
||||||
|
// empty string
|
||||||
|
"",
|
||||||
|
'',
|
||||||
|
|
||||||
|
// null vlaues
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
//resource
|
||||||
|
$file_handle,
|
||||||
|
|
||||||
|
// undefined variable
|
||||||
|
@$undefined_var,
|
||||||
|
|
||||||
|
// unset variable
|
||||||
|
@$unset_var
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// loop through each element of the array and check the working of strrpos()
|
||||||
|
$counter = 1;
|
||||||
|
for($index = 0; $index < count($offsets); $index ++) {
|
||||||
|
echo "-- Iteration $counter --\n";
|
||||||
|
var_dump( strrpos($haystack, $needle, $offsets[$index]) );
|
||||||
|
$counter ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with unexpected values for offset ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 2 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 12 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 13 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 14 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 15 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, object given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 20 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, resource given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(6)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with unexpected values for offset ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 2 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 12 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 13 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 14 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 15 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, object given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, Unicode string given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, Unicode string given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 20 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, resource given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(6)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(6)
|
||||||
|
*** Done ***
|
260
ext/standard/tests/strings/strrpos_variation15.phpt
Normal file
260
ext/standard/tests/strings/strrpos_variation15.phpt
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - unexpected inputs for 'haystack', 'needle' & 'offset' arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with unexpected inputs for 'haystack', 'needle' & 'offset' arguments */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***\n";
|
||||||
|
|
||||||
|
// get an unset variable
|
||||||
|
$unset_var = 'string_val';
|
||||||
|
unset($unset_var);
|
||||||
|
|
||||||
|
// defining a class
|
||||||
|
class sample {
|
||||||
|
public function __toString() {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//getting the resource
|
||||||
|
$file_handle = fopen(__FILE__, "r");
|
||||||
|
|
||||||
|
// array with different values
|
||||||
|
$values = array (
|
||||||
|
|
||||||
|
// integer values
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
12345,
|
||||||
|
-2345,
|
||||||
|
|
||||||
|
// float values
|
||||||
|
10.5,
|
||||||
|
-10.5,
|
||||||
|
10.5e10,
|
||||||
|
10.6E-10,
|
||||||
|
.5,
|
||||||
|
|
||||||
|
// array values
|
||||||
|
array(),
|
||||||
|
array(0),
|
||||||
|
array(1),
|
||||||
|
array(1, 2),
|
||||||
|
array('color' => 'red', 'item' => 'pen'),
|
||||||
|
|
||||||
|
// boolean values
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
// objects
|
||||||
|
new sample(),
|
||||||
|
|
||||||
|
// empty string
|
||||||
|
"",
|
||||||
|
'',
|
||||||
|
|
||||||
|
// null vlaues
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
//resource
|
||||||
|
$file_handle,
|
||||||
|
|
||||||
|
// undefined variable
|
||||||
|
@$undefined_var,
|
||||||
|
|
||||||
|
// unset variable
|
||||||
|
@$unset_var
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// loop through each element of the array and check the working of strrpos()
|
||||||
|
$counter = 1;
|
||||||
|
for($index = 0; $index < count($values); $index ++) {
|
||||||
|
echo "-- Iteration $counter --\n";
|
||||||
|
var_dump( strrpos($values[$index], $values[$index], $values[$index]) );
|
||||||
|
$counter ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, object given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, resource given in %s on line %d%d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 2 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 6 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
|
||||||
|
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, array given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, object given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, Unicode string given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, Unicode string given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 24 --
|
||||||
|
|
||||||
|
Warning: strrpos() expects parameter 3 to be long, resource given in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
299
ext/standard/tests/strings/strrpos_variation2.phpt
Normal file
299
ext/standard/tests/strings/strrpos_variation2.phpt
Normal file
@ -0,0 +1,299 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - single quoted strings for 'haystack' & 'needle' arguments
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing single quoted strings to 'haystack' & 'needle' arguments */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with single quoted strings ***\n";
|
||||||
|
$haystack = 'Hello,\t\n\0\n $&!#%()*<=>?@hello123456he \x234 \101 ';
|
||||||
|
$needle = array(
|
||||||
|
//regular strings
|
||||||
|
'l',
|
||||||
|
'L',
|
||||||
|
'HELLO',
|
||||||
|
'hEllo',
|
||||||
|
|
||||||
|
//escape characters
|
||||||
|
'\t',
|
||||||
|
'\T',
|
||||||
|
' ',
|
||||||
|
'\n',
|
||||||
|
'\N',
|
||||||
|
'
|
||||||
|
', //new line
|
||||||
|
|
||||||
|
//nulls
|
||||||
|
'\0',
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
//boolean false
|
||||||
|
FALSE,
|
||||||
|
false,
|
||||||
|
|
||||||
|
//empty string
|
||||||
|
'',
|
||||||
|
|
||||||
|
//special chars
|
||||||
|
' ',
|
||||||
|
'$',
|
||||||
|
' $',
|
||||||
|
'&',
|
||||||
|
'!#',
|
||||||
|
'()',
|
||||||
|
'<=>',
|
||||||
|
'>',
|
||||||
|
'=>',
|
||||||
|
'?',
|
||||||
|
'@',
|
||||||
|
'@hEllo',
|
||||||
|
|
||||||
|
'12345', //decimal numeric string
|
||||||
|
'\x23', //hexadecimal numeric string
|
||||||
|
'#', //hexadecimal numeric string
|
||||||
|
'\101', //octal numeric string
|
||||||
|
'A',
|
||||||
|
'456HEE', //numerics + chars
|
||||||
|
42, //needle as int(ASCII value of '*')
|
||||||
|
$haystack //haystack as needle
|
||||||
|
);
|
||||||
|
|
||||||
|
/* loop through to get the position of the needle in haystack string */
|
||||||
|
$count = 1;
|
||||||
|
for($index=0; $index<count($needle); $index++) {
|
||||||
|
echo "-- Iteration $count --\n";
|
||||||
|
var_dump( strrpos($haystack, $needle[$index]) );
|
||||||
|
var_dump( strrpos($haystack, $needle[$index], $index) );
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with single quoted strings ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(32)
|
||||||
|
int(32)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
int(12)
|
||||||
|
int(12)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(10)
|
||||||
|
int(10)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
int(53)
|
||||||
|
int(53)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(16)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(15)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
int(17)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(18)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(21)
|
||||||
|
int(21)
|
||||||
|
-- Iteration 23 --
|
||||||
|
int(24)
|
||||||
|
int(24)
|
||||||
|
-- Iteration 24 --
|
||||||
|
int(26)
|
||||||
|
int(26)
|
||||||
|
-- Iteration 25 --
|
||||||
|
int(25)
|
||||||
|
int(25)
|
||||||
|
-- Iteration 26 --
|
||||||
|
int(27)
|
||||||
|
int(27)
|
||||||
|
-- Iteration 27 --
|
||||||
|
int(28)
|
||||||
|
int(28)
|
||||||
|
-- Iteration 28 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 29 --
|
||||||
|
int(34)
|
||||||
|
int(34)
|
||||||
|
-- Iteration 30 --
|
||||||
|
int(43)
|
||||||
|
int(43)
|
||||||
|
-- Iteration 31 --
|
||||||
|
int(19)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 32 --
|
||||||
|
int(49)
|
||||||
|
int(49)
|
||||||
|
-- Iteration 33 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 34 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 35 --
|
||||||
|
int(23)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 36 --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with single quoted strings ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(32)
|
||||||
|
int(32)
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(6)
|
||||||
|
int(6)
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
int(12)
|
||||||
|
int(12)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
int(10)
|
||||||
|
int(10)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 17 --
|
||||||
|
int(53)
|
||||||
|
int(53)
|
||||||
|
-- Iteration 18 --
|
||||||
|
int(16)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 19 --
|
||||||
|
int(15)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 20 --
|
||||||
|
int(17)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 21 --
|
||||||
|
int(18)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 22 --
|
||||||
|
int(21)
|
||||||
|
int(21)
|
||||||
|
-- Iteration 23 --
|
||||||
|
int(24)
|
||||||
|
int(24)
|
||||||
|
-- Iteration 24 --
|
||||||
|
int(26)
|
||||||
|
int(26)
|
||||||
|
-- Iteration 25 --
|
||||||
|
int(25)
|
||||||
|
int(25)
|
||||||
|
-- Iteration 26 --
|
||||||
|
int(27)
|
||||||
|
int(27)
|
||||||
|
-- Iteration 27 --
|
||||||
|
int(28)
|
||||||
|
int(28)
|
||||||
|
-- Iteration 28 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 29 --
|
||||||
|
int(34)
|
||||||
|
int(34)
|
||||||
|
-- Iteration 30 --
|
||||||
|
int(43)
|
||||||
|
int(43)
|
||||||
|
-- Iteration 31 --
|
||||||
|
int(19)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 32 --
|
||||||
|
int(49)
|
||||||
|
int(49)
|
||||||
|
-- Iteration 33 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 34 --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 35 --
|
||||||
|
int(23)
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 36 --
|
||||||
|
int(0)
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
46
ext/standard/tests/strings/strrpos_variation3.phpt
Normal file
46
ext/standard/tests/strings/strrpos_variation3.phpt
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - multi line heredoc string for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing multi-line heredoc string for haystack and
|
||||||
|
* with various needles & offsets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with heredoc strings ***\n";
|
||||||
|
echo "-- With heredoc string containing multi lines --\n";
|
||||||
|
$multi_line_str = <<<EOD
|
||||||
|
Example of string
|
||||||
|
spanning multiple lines
|
||||||
|
using heredoc syntax.
|
||||||
|
EOD;
|
||||||
|
var_dump( strrpos($multi_line_str, "ing", 0) );
|
||||||
|
var_dump( strrpos($multi_line_str, "ing", 15) );
|
||||||
|
var_dump( strrpos($multi_line_str, "ing", 22) );
|
||||||
|
var_dump( strrpos($multi_line_str, "") );
|
||||||
|
var_dump( strrpos($multi_line_str, " ") );
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing multi lines --
|
||||||
|
int(44)
|
||||||
|
int(44)
|
||||||
|
int(44)
|
||||||
|
bool(false)
|
||||||
|
int(55)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing multi lines --
|
||||||
|
int(44)
|
||||||
|
int(44)
|
||||||
|
int(44)
|
||||||
|
bool(false)
|
||||||
|
int(55)
|
||||||
|
*** Done ***
|
52
ext/standard/tests/strings/strrpos_variation4.phpt
Normal file
52
ext/standard/tests/strings/strrpos_variation4.phpt
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - heredoc string containing special chars for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing heredoc string containing special chars for haystack
|
||||||
|
* and with various needles & offets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with heredoc strings ***\n";
|
||||||
|
echo "-- With heredoc string containing special chars --\n";
|
||||||
|
$special_chars_str = <<<EOD
|
||||||
|
Ex'ple of h'doc st'g, contains
|
||||||
|
$#%^*&*_("_")!#@@!$#$^^&$*(special)
|
||||||
|
chars.
|
||||||
|
EOD;
|
||||||
|
var_dump( strrpos($special_chars_str, "Ex'ple", 0) );
|
||||||
|
var_dump( strrpos($special_chars_str, "!@@!", 23) );
|
||||||
|
var_dump( strrpos($special_chars_str, '_') );
|
||||||
|
var_dump( strrpos($special_chars_str, '("_")') );
|
||||||
|
var_dump( strrpos($special_chars_str, "$*") );
|
||||||
|
var_dump( strrpos($special_chars_str, "$*", 10) );
|
||||||
|
var_dump( strrpos($special_chars_str, "(special)") );
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing special chars --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(41)
|
||||||
|
int(39)
|
||||||
|
int(55)
|
||||||
|
int(55)
|
||||||
|
int(57)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing special chars --
|
||||||
|
int(0)
|
||||||
|
bool(false)
|
||||||
|
int(41)
|
||||||
|
int(39)
|
||||||
|
int(55)
|
||||||
|
int(55)
|
||||||
|
int(57)
|
||||||
|
*** Done ***
|
42
ext/standard/tests/strings/strrpos_variation5.phpt
Normal file
42
ext/standard/tests/strings/strrpos_variation5.phpt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - heredoc string containing escape chars for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing heredoc string containing escape chars for haystack
|
||||||
|
* and with various needles & offsets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with heredoc strings ***\n";
|
||||||
|
echo "-- With heredoc string containing escape characters --\n";
|
||||||
|
$control_char_str = <<<EOD
|
||||||
|
Hello, World\n
|
||||||
|
Hello\tWorld
|
||||||
|
EOD;
|
||||||
|
var_dump( strrpos($control_char_str, "\n") );
|
||||||
|
var_dump( strrpos($control_char_str, "\t") );
|
||||||
|
var_dump( strrpos($control_char_str, "\n", 12) );
|
||||||
|
var_dump( strrpos($control_char_str, "\t", 15) );
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing escape characters --
|
||||||
|
int(13)
|
||||||
|
int(19)
|
||||||
|
int(13)
|
||||||
|
int(19)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing escape characters --
|
||||||
|
int(13)
|
||||||
|
int(19)
|
||||||
|
int(13)
|
||||||
|
int(19)
|
||||||
|
*** Done ***
|
43
ext/standard/tests/strings/strrpos_variation6.phpt
Normal file
43
ext/standard/tests/strings/strrpos_variation6.phpt
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - heredoc string containing quotes for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing heredoc string containing quotes for haystack
|
||||||
|
* and with various needles & offsets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with heredoc strings ***\n";
|
||||||
|
echo "-- With heredoc string containing quote & slash chars --\n";
|
||||||
|
$quote_char_str = <<<EOD
|
||||||
|
it's bright,but i cann't see it.
|
||||||
|
"things in double quote"
|
||||||
|
'things in single quote'
|
||||||
|
this\line is /with\slashs
|
||||||
|
EOD;
|
||||||
|
var_dump( strrpos($quote_char_str, "line") );
|
||||||
|
var_dump( strrpos($quote_char_str, 'things') );
|
||||||
|
var_dump( strrpos($quote_char_str, 'things', 0) );
|
||||||
|
var_dump( strrpos($quote_char_str, "things", 20) );
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing quote & slash chars --
|
||||||
|
int(88)
|
||||||
|
int(59)
|
||||||
|
int(59)
|
||||||
|
int(59)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With heredoc string containing quote & slash chars --
|
||||||
|
int(88)
|
||||||
|
int(59)
|
||||||
|
int(59)
|
||||||
|
int(59)
|
||||||
|
*** Done ***
|
32
ext/standard/tests/strings/strrpos_variation7.phpt
Normal file
32
ext/standard/tests/strings/strrpos_variation7.phpt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - empty heredoc string for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function by passing empty heredoc string for haystack
|
||||||
|
* and with various needles & offsets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: with heredoc strings ***\n";
|
||||||
|
echo "-- With empty heredoc string --\n";
|
||||||
|
$empty_string = <<<EOD
|
||||||
|
EOD;
|
||||||
|
var_dump( strrpos($empty_string, "") );
|
||||||
|
var_dump( strrpos($empty_string, "", 1) );
|
||||||
|
var_dump( strrpos($empty_string, FALSE) );
|
||||||
|
var_dump( strrpos($empty_string, NULL) );
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: with heredoc strings ***
|
||||||
|
-- With empty heredoc string --
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
98
ext/standard/tests/strings/strrpos_variation8.phpt
Normal file
98
ext/standard/tests/strings/strrpos_variation8.phpt
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - repetitive chars for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with strings containing multiple occurrences of 'needle' in the 'haystack'
|
||||||
|
* and with various needles & offsets
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function: strings repetitive chars ***\n";
|
||||||
|
$haystack = "ababababAbaBa";
|
||||||
|
$needle = "aba";
|
||||||
|
|
||||||
|
/* loop through to consider various offsets in getting the position of the needle in haystack string */
|
||||||
|
$count = 1;
|
||||||
|
for($offset = -1; $offset <= strlen($haystack); $offset++ ) {
|
||||||
|
echo "-- Iteration $count --\n";
|
||||||
|
var_dump( strrpos($haystack, $needle, $offset) );
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function: strings repetitive chars ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 2 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 3 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 4 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 6 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function: strings repetitive chars ***
|
||||||
|
-- Iteration 1 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 2 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 3 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 4 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 5 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 6 --
|
||||||
|
int(4)
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 10 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 11 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 12 --
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
-- Iteration 15 --
|
||||||
|
|
||||||
|
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
273
ext/standard/tests/strings/strrpos_variation9.phpt
Normal file
273
ext/standard/tests/strings/strrpos_variation9.phpt
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
--TEST--
|
||||||
|
Test strrpos() function : usage variations - unexpected inputs for 'haystack' argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
|
||||||
|
* Description: Find position of last occurrence of 'needle' in 'haystack'.
|
||||||
|
* Source code: ext/standard/string.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Test strrpos() function with unexpected inputs for haystack argument */
|
||||||
|
|
||||||
|
echo "*** Testing strrpos() function with unexpected values for haystack ***\n";
|
||||||
|
|
||||||
|
// get an unset variable
|
||||||
|
$unset_var = 'string_val';
|
||||||
|
unset($unset_var);
|
||||||
|
|
||||||
|
// defining a class
|
||||||
|
class sample {
|
||||||
|
public function __toString() {
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//getting the resource
|
||||||
|
$file_handle = fopen(__FILE__, "r");
|
||||||
|
|
||||||
|
// array with different values
|
||||||
|
$haystacks = array (
|
||||||
|
|
||||||
|
// integer values
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
12345,
|
||||||
|
-2345,
|
||||||
|
|
||||||
|
// float values
|
||||||
|
10.5,
|
||||||
|
-10.5,
|
||||||
|
10.5e10,
|
||||||
|
10.6E-10,
|
||||||
|
.5,
|
||||||
|
|
||||||
|
// array values
|
||||||
|
array(),
|
||||||
|
array(0),
|
||||||
|
array(1),
|
||||||
|
array(1, 2),
|
||||||
|
array('color' => 'red', 'item' => 'pen'),
|
||||||
|
|
||||||
|
// boolean values
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
// objects
|
||||||
|
new sample(),
|
||||||
|
|
||||||
|
// empty string
|
||||||
|
"",
|
||||||
|
'',
|
||||||
|
|
||||||
|
// null vlaues
|
||||||
|
NULL,
|
||||||
|
null,
|
||||||
|
|
||||||
|
// resource
|
||||||
|
$file_handle,
|
||||||
|
|
||||||
|
// undefined variable
|
||||||
|
@$undefined_var,
|
||||||
|
|
||||||
|
// unset variable
|
||||||
|
@$unset_var
|
||||||
|
);
|
||||||
|
|
||||||
|
$needle = "heredoc 0 1 2 -2 10.5 -10.5 10.5e10 10.6E-10 .5 array true false object \"\" null Resource";
|
||||||
|
|
||||||
|
// loop through each element of the array and check the working of strrpos()
|
||||||
|
$counter = 1;
|
||||||
|
for($index = 0; $index < count($haystacks); $index ++) {
|
||||||
|
echo "\n-- Iteration $counter --\n";
|
||||||
|
var_dump( strrpos($haystacks[$index], $needle) );
|
||||||
|
$counter ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($file_handle); //closing the file handle
|
||||||
|
|
||||||
|
echo "*** Done ***";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for haystack ***
|
||||||
|
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 19 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
||||||
|
--UEXPECTF--
|
||||||
|
*** Testing strrpos() function with unexpected values for haystack ***
|
||||||
|
|
||||||
|
-- Iteration 1 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 2 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 3 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 4 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 5 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 6 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 7 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 8 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 9 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 10 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 11 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 12 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 13 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 14 --
|
||||||
|
|
||||||
|
Notice: Array to string conversion in %s on line %d
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 15 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 16 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 17 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 18 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 19 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 20 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 21 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 22 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 23 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 24 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 25 --
|
||||||
|
bool(false)
|
||||||
|
|
||||||
|
-- Iteration 26 --
|
||||||
|
bool(false)
|
||||||
|
*** Done ***
|
Loading…
Reference in New Issue
Block a user