--- /dev/null
+--TEST--
+Test strrchr() function : basic functionality
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing strrchr() function: basic functionality ***\n";
+var_dump( strrchr("Hello, World", "H") ); //needle as single char
+var_dump( strrchr("Hello, World", "Hello") ); //needle as a first word of haystack
+var_dump( strrchr('Hello, World', 'H') );
+var_dump( strrchr('Hello, World', 'Hello') );
+
+//considering case
+var_dump( strrchr("Hello, World", "h") );
+var_dump( strrchr("Hello, World", "hello") );
+
+//needle as second word of haystack
+var_dump( strrchr("Hello, World", "World") );
+var_dump( strrchr('Hello, World', 'World') );
+
+//needle as special char
+var_dump( strrchr("Hello, World", ",") );
+var_dump( strrchr('Hello, World', ',') );
+
+var_dump( strrchr("Hello, World", "Hello, World") ); //needle as haystack
+
+//needle string containing one existing and one non-existing char
+var_dump( strrchr("Hello, World", "Hi") );
+
+//multiple existance of needle in haystack
+var_dump( strrchr("Hello, World", "o") );
+var_dump( strrchr("Hello, World", "ooo") );
+
+var_dump( strrchr("Hello, World", "Zzzz") ); //non-existant needle in haystack
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: basic functionality ***
+string(12) "Hello, World"
+string(12) "Hello, World"
+string(12) "Hello, World"
+string(12) "Hello, World"
+bool(false)
+bool(false)
+string(5) "World"
+string(5) "World"
+string(7) ", World"
+string(7) ", World"
+string(12) "Hello, World"
+string(12) "Hello, World"
+string(4) "orld"
+string(4) "orld"
+bool(false)
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : error conditions
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing strrchr() function: error conditions ***\n";
+$haystack = "Hello";
+$needle = "Hello";
+$extra_arg = "Hello";
+
+echo "\n-- Testing strrchr() function with Zero arguments --";
+var_dump( strrchr() );
+
+echo "\n-- Testing strrchr() function with less than expected no. of arguments --";
+var_dump( strrchr($haystack) );
+
+echo "\n-- Testing strrchr() function with more than expected no. of arguments --";
+var_dump( strrchr($haystack, $needle, $extra_arg) );
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: error conditions ***
+
+-- Testing strrchr() function with Zero arguments --
+Warning: Wrong parameter count for strrchr() in %s on line %d
+NULL
+
+-- Testing strrchr() function with less than expected no. of arguments --
+Warning: Wrong parameter count for strrchr() in %s on line %d
+NULL
+
+-- Testing strrchr() function with more than expected no. of arguments --
+Warning: Wrong parameter count for strrchr() in %s on line %d
+NULL
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - unexpected inputs for needle
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function: with unexpected inputs for needle
+ * and expected type for haystack
+*/
+
+echo "*** Testing strrchr() function with unexpected inputs for needle ***\n";
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring a class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+$haystacks = array (
+ //integer numeric strings
+ "0",
+ "1",
+ "2",
+ "-2",
+
+ //float numeric strings
+ "10.5",
+ "-10.5",
+ "10.5e10",
+ "10.6E-10",
+ ".5",
+
+ //regular strings
+ "array",
+ "a",
+ "r",
+ "y",
+ "ay",
+ "true",
+ "false",
+ "TRUE",
+ "FALSE",
+ "NULL",
+ "null",
+ "object",
+
+ //empty string
+ "",
+ '',
+
+ //resource variable in string form
+ "\$file_handle",
+
+ //undefined variable in string form
+ @"$undefined_var",
+ @"$unset_var"
+);
+
+// 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,
+
+ // null vlaues
+ NULL,
+ null,
+
+ // objects
+ new sample(),
+
+ // empty string
+ "",
+ '',
+
+ // resource
+ $file_handle,
+
+ // undefined variable
+ @$undefined_var,
+
+ // unset variable
+ @$unset_var
+);
+
+// loop through each element of the array and check the working of strrchr()
+$count = 1;
+for($index = 0; $index < count($haystacks); $index++) {
+ echo "-- Iteration $count --\n";
+ var_dump( strrchr($haystacks[$index], $needles[$index]) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function with unexpected inputs 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 --
+bool(false)
+-- Iteration 20 --
+bool(false)
+-- Iteration 21 --
+
+Notice: Object of class sample could not be converted to int in %s on line %d
+bool(false)
+-- Iteration 22 --
+bool(false)
+-- Iteration 23 --
+bool(false)
+-- Iteration 24 --
+bool(false)
+-- Iteration 25 --
+bool(false)
+-- Iteration 26 --
+bool(false)
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - unexpected inputs for haystack and needle
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function with unexpected inputs for haystack and needle */
+
+echo "*** Testing strrchr() function: with unexpected inputs for haystack and needle ***\n";
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring 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 strrchr()
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+ echo "-- Iteration $counter --\n";
+ $haystack = $values[$index];
+
+ var_dump( strrchr($values[$index], $values[$index]) );
+ $counter ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with unexpected inputs for haystack and 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 --
+
+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 --
+
+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 ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - single quoted strings
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing various single quoted strings to 'haystack' & 'needle' */
+
+echo "*** Testing strrchr() function: with various single quoted strings ***";
+$haystack = 'Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@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
+ ' ',
+ '$',
+ ' $',
+ '&',
+ '!#',
+ '%\o',
+ '\o,',
+ '()',
+ '*+',
+ '+',
+ '-',
+ '.',
+ '.;',
+ ':;',
+ ';',
+ '<=>',
+ '>',
+ '=>',
+ '?',
+ '@',
+ '@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 "\n-- Iteration $count --\n";
+ var_dump( strrchr($haystack, $needle[$index]) );
+ $count ++;
+}
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with various single quoted strings ***
+-- Iteration 1 --
+string(22) "lo123456he \x234 \101 "
+
+-- Iteration 2 --
+bool(false)
+
+-- Iteration 3 --
+string(63) "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 4 --
+string(14) "he \x234 \101 "
+
+-- Iteration 5 --
+string(5) "\101 "
+
+-- Iteration 6 --
+string(5) "\101 "
+
+-- Iteration 7 --
+string(1) " "
+
+-- Iteration 8 --
+string(5) "\101 "
+
+-- Iteration 9 --
+string(5) "\101 "
+
+-- Iteration 10 --
+bool(false)
+
+-- Iteration 11 --
+string(5) "\101 "
+
+-- Iteration 12 --
+bool(false)
+
+-- Iteration 13 --
+bool(false)
+
+-- Iteration 14 --
+bool(false)
+
+-- Iteration 15 --
+bool(false)
+
+-- Iteration 16 --
+bool(false)
+
+-- Iteration 17 --
+string(1) " "
+
+-- Iteration 18 --
+string(47) "$&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 19 --
+string(1) " "
+
+-- Iteration 20 --
+string(46) "&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 21 --
+string(45) "!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 22 --
+string(43) "%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 23 --
+string(5) "\101 "
+
+-- Iteration 24 --
+string(39) "()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 25 --
+string(37) "*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 26 --
+string(36) "+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 27 --
+string(35) "-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 28 --
+string(34) "./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 29 --
+string(34) "./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 30 --
+string(32) ":;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 31 --
+string(31) ";<=>?@hello123456he \x234 \101 "
+
+-- Iteration 32 --
+string(30) "<=>?@hello123456he \x234 \101 "
+
+-- Iteration 33 --
+string(28) ">?@hello123456he \x234 \101 "
+
+-- Iteration 34 --
+string(29) "=>?@hello123456he \x234 \101 "
+
+-- Iteration 35 --
+string(27) "?@hello123456he \x234 \101 "
+
+-- Iteration 36 --
+string(26) "@hello123456he \x234 \101 "
+
+-- Iteration 37 --
+string(26) "@hello123456he \x234 \101 "
+
+-- Iteration 38 --
+string(2) "1 "
+
+-- Iteration 39 --
+string(5) "\101 "
+
+-- Iteration 40 --
+string(44) "#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 41 --
+string(5) "\101 "
+
+-- Iteration 42 --
+bool(false)
+
+-- Iteration 43 --
+string(7) "4 \101 "
+
+-- Iteration 44 --
+string(37) "*+-./:;<=>?@hello123456he \x234 \101 "
+
+-- Iteration 45 --
+string(63) "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - multi line heredoc string for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing multi-line heredoc string for haystack and
+ * with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$multi_line_str = <<<EOD
+Example of string
+spanning multiple lines
+using heredoc syntax.
+EOD;
+
+$needles = array(
+ "ing",
+ "",
+ " ",
+ $multi_line_str //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($multi_line_str, $needle) );
+}
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+string(19) "ing heredoc syntax."
+bool(false)
+string(8) " syntax."
+string(63) "Example of string
+spanning multiple lines
+using heredoc syntax."
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - heredoc string containing special chars for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing heredoc string containing special chars for haystack
+ * and with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$special_chars_str = <<<EOD
+Example of heredoc string contains
+$#%^*&*_("_")!#@@!$#$^^&*(special)
+chars.
+EOD;
+
+$heredoc_needle = <<<EOD
+^^&*(
+EOD;
+
+$needles = array(
+ "!@@!",
+ '_',
+ '("_")',
+ "$*",
+ "(special)",
+ $heredoc_needle, //needle as heredoc string
+ $special_chars_str //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($special_chars_str, $needle) );
+}
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+string(24) "!$#$^^&*(special)
+chars."
+string(31) "_")!#@@!$#$^^&*(special)
+chars."
+string(16) "(special)
+chars."
+string(21) "$^^&*(special)
+chars."
+string(16) "(special)
+chars."
+string(19) "^&*(special)
+chars."
+string(76) "Example of heredoc string contains
+$#%^*&*_("_")!#@@!$#$^^&*(special)
+chars."
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - heredoc string containing escape sequences for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing heredoc string containing
+ * escape sequences for haystack and with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$escape_char_str = <<<EOD
+\tes\t st\r\rch\r using
+\escape \\seque\nce
+EOD;
+
+$needles = array(
+ "\t",
+ '\n',
+ "\r",
+ "\\",
+ $escape_char_str //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($escape_char_str, $needle) );
+}
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+string(33) " st
+
+ch
+ using
+\escape \seque
+ce"
+string(9) "\seque
+ce"
+string(25) "
+ using
+\escape \seque
+ce"
+string(9) "\seque
+ce"
+string(33) " st
+
+ch
+ using
+\escape \seque
+ce"
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - heredoc string containing quote chars for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing heredoc string containing quote chars for haystack
+ * and with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$quote_char_str = <<<EOD
+"things" "in" "double" "quote"
+'things' 'in' 'single' 'quote'
+EOD;
+
+$needles = array(
+ "things",
+ "\"things\"",
+ "\'things\'",
+ "in",
+ "quote",
+ $quote_char_str //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($quote_char_str, $needle) );
+}
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+string(3) "te'"
+string(32) ""
+'things' 'in' 'single' 'quote'"
+bool(false)
+string(14) "ingle' 'quote'"
+string(6) "quote'"
+string(32) ""
+'things' 'in' 'single' 'quote'"
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - heredoc string containing blank line for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing heredoc string containing
+ * blank-line for haystack and with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$blank_line = <<<EOD
+
+EOD;
+
+$needles = array(
+ "\n",
+ '\n',
+ "\r",
+ "\r\n",
+ "\t",
+ "",
+ $blank_line //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($blank_line, $needle) );
+}
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+string(1) "
+"
+bool(false)
+bool(false)
+string(1) "
+"
+bool(false)
+bool(false)
+string(1) "
+"
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - empty heredoc string for 'haystack'
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function by passing empty heredoc string for haystack
+ * and with various needles
+*/
+
+echo "*** Testing strrchr() function: with heredoc strings ***\n";
+$empty_str = <<<EOD
+EOD;
+
+$needles = array(
+ "",
+ '',
+ FALSE,
+ NULL,
+ "\0",
+ $empty_str //needle as haystack
+);
+
+//loop through to test strrchr() with each needle
+foreach($needles as $needle) {
+ var_dump( strrchr($empty_str, $needle) );
+}
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with heredoc strings ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+*** Done ***
--- /dev/null
+--TEST--
+Test strrchr() function : usage variations - unexpected inputs for haystack
+--FILE--
+<?php
+/* Prototype : string strrchr(string $haystack, string $needle);
+ * Description: Finds the last occurrence of a character in a string.
+ * Source code: ext/standard/string.c
+*/
+
+/* Test strrchr() function with unexpected inputs for haystack
+ * and expected type for 'needle'
+*/
+
+echo "*** Testing strrchr() function: with unexpected inputs for haystack ***\n";
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring 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,
+
+ // null vlaues
+ NULL,
+ null,
+
+ // objects
+ new sample(),
+
+ // empty string
+ "",
+ '',
+
+ // resource
+ $file_handle,
+
+ // undefined variable
+ @$undefined_var,
+
+ // unset variable
+ @$unset_var
+);
+
+$needles = array (
+ //integer numeric strings
+ "0",
+ "1",
+ "2",
+ "-2",
+
+ //float numeric strings
+ "10.5",
+ "-10.5",
+ "10.5e10",
+ "10.6E-10",
+ ".5",
+
+ //regular strings
+ "array",
+ "a",
+ "r",
+ "y",
+ "ay",
+ "true",
+ "false",
+ "TRUE",
+ "FALSE",
+ "NULL",
+ "null",
+ "object",
+
+ //empty string
+ "",
+ '',
+
+ //resource variable in string form
+ "\$file_handle",
+
+ //undefined variable in string form
+ @"$undefined_var",
+ @"$unset_var"
+);
+
+// loop through each element of the array and check the working of strrchr()
+$count = 1;
+for($index = 0; $index < count($haystacks); $index++) {
+ echo "-- Iteration $count --\n";
+ var_dump( strrchr($haystacks[$index], $needles[$index]) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+echo "*** Done ***";
+?>
+--EXPECTF--
+*** Testing strrchr() function: with unexpected inputs for haystack ***
+-- Iteration 1 --
+string(1) "0"
+-- Iteration 2 --
+string(1) "1"
+-- Iteration 3 --
+string(4) "2345"
+-- Iteration 4 --
+string(5) "-2345"
+-- Iteration 5 --
+string(4) "10.5"
+-- Iteration 6 --
+string(5) "-10.5"
+-- Iteration 7 --
+string(12) "105000000000"
+-- Iteration 8 --
+string(7) "1.06E-9"
+-- Iteration 9 --
+string(2) ".5"
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+string(2) "ay"
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+string(2) "ay"
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+string(3) "ray"
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line %d
+string(1) "y"
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line %d
+string(2) "ay"
+-- 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 --
+string(6) "object"
+-- Iteration 22 --
+bool(false)
+-- Iteration 23 --
+bool(false)
+-- Iteration 24 --
+bool(false)
+-- Iteration 25 --
+bool(false)
+-- Iteration 26 --
+bool(false)
+*** Done ***