--- /dev/null
+--TEST--
+Test print() function : basic functionality
+--FILE--
+<?php
+
+/* Prototype : int print ( string $arg )
+ * Description: Output a string
+ * Source code: n/a, print is a language construct not an extension function
+ * Test based on php.net manual example.
+*/
+
+echo "*** Testing print() : basic functionality ***\n";
+
+echo "\n-- Iteration 1 --\n";
+print("Hello World");
+
+echo "\n-- Iteration 2 --\n";
+print "print() also works without parentheses.";
+
+echo "\n-- Iteration 3 --\n";
+print "This spans
+multiple lines. The newlines will be
+output as well";
+
+echo "\n-- Iteration 4 --\n";
+print "This also spans\nmultiple lines. The newlines will be\noutput as well.";
+
+echo "\n-- Iteration 5 --\n";
+print "escaping characters is done \"Like this\".";
+
+// You can use variables inside of a print statement
+$foo = "foobar";
+$bar = "barbaz";
+
+echo "\n-- Iteration 6 --\n";
+print "foo is $foo"; // foo is foobar
+
+// You can also use arrays
+$bar = array("value" => "foo");
+
+echo "\n-- Iteration 7 --\n";
+print "this is {$bar['value']} !"; // this is foo !
+
+// Using single quotes will print the variable name, not the value
+echo "\n-- Iteration 8 --\n";
+print 'foo is $foo'; // foo is $foo
+
+// If you are not using any other characters, you can just print variables
+echo "\n-- Iteration 9 --\n";
+print $foo; // foobar
+
+echo "\n-- Iteration 10 --\n";
+$variable = "VARIABLE";
+print <<<END
+This uses the "here document" syntax to output
+multiple lines with $variable interpolation. Note
+that the here document terminator must appear on a
+line with just a semicolon no extra whitespace!\n
+END;
+?>
+===DONE===
+--EXPECT--
+*** Testing print() : basic functionality ***
+
+-- Iteration 1 --
+Hello World
+-- Iteration 2 --
+print() also works without parentheses.
+-- Iteration 3 --
+This spans
+multiple lines. The newlines will be
+output as well
+-- Iteration 4 --
+This also spans
+multiple lines. The newlines will be
+output as well.
+-- Iteration 5 --
+escaping characters is done "Like this".
+-- Iteration 6 --
+foo is foobar
+-- Iteration 7 --
+this is foo !
+-- Iteration 8 --
+foo is $foo
+-- Iteration 9 --
+foobar
+-- Iteration 10 --
+This uses the "here document" syntax to output
+multiple lines with VARIABLE interpolation. Note
+that the here document terminator must appear on a
+line with just a semicolon no extra whitespace!
+===DONE===
--- /dev/null
+--TEST--
+Test print() function : usage variations
+--FILE--
+<?php
+
+/* Prototype : int print ( string $arg )
+ * Description: Output a string
+ * Source code: n/a, print is a language construct not an extension function
+ * Test based on php.net manual example.
+*/
+
+echo "*** Testing print() function: with unexpected inputs for 'arg' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return "sample object";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $input
+$inputs = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ -2,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*6*/ 10.5,
+ -20.5,
+ 10.1234567e10,
+
+ // array values
+/*9*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null vlaues
+/*16*/ NULL,
+ null,
+
+ // objects
+/*18*/ new sample(),
+
+ // resource
+/*19*/ $file_handle,
+
+ // undefined variable
+/*20*/ @$undefined_var,
+
+ // unset variable
+/*21*/ @$unset_var
+);
+
+// loop through with each element of the $inputs array to test print() function
+$count = 1;
+foreach($inputs as $input) {
+ echo "-- Iteration $count --\n";
+ $res = print($input);
+ echo "\n";
+ var_dump($res);
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing print() function: with unexpected inputs for 'arg' argument ***
+-- Iteration 1 --
+0
+int(1)
+-- Iteration 2 --
+1
+int(1)
+-- Iteration 3 --
+-2
+int(1)
+-- Iteration 4 --
+2147483647
+int(1)
+-- Iteration 5 --
+-2147483648
+int(1)
+-- Iteration 6 --
+10.5
+int(1)
+-- Iteration 7 --
+-20.5
+int(1)
+-- Iteration 8 --
+101234567000
+int(1)
+-- Iteration 9 --
+Array
+int(1)
+-- Iteration 10 --
+Array
+int(1)
+-- Iteration 11 --
+Array
+int(1)
+-- Iteration 12 --
+1
+int(1)
+-- Iteration 13 --
+
+int(1)
+-- Iteration 14 --
+1
+int(1)
+-- Iteration 15 --
+
+int(1)
+-- Iteration 16 --
+
+int(1)
+-- Iteration 17 --
+
+int(1)
+-- Iteration 18 --
+sample object
+int(1)
+-- Iteration 19 --
+Resource id #%d
+int(1)
+-- Iteration 20 --
+
+int(1)
+-- Iteration 21 --
+
+int(1)
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - string format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using string format ***\n";
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%s";
+$format2 = "%s %s";
+$format3 = "%s %s %s";
+$arg1 = "arg1 argument";
+$arg2 = "arg2 argument";
+$arg3 = "arg3 argument";
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+
+echo "\n-- Calling printf() with string three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using string format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments --
+arg1 argument
+int(13)
+
+-- Calling printf() with two arguments --
+arg1 argument arg2 argument
+int(27)
+
+-- Calling printf() with string three arguments --
+arg1 argument arg2 argument arg3 argument
+int(41)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - integer format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using integer format ***\n";
+
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%d";
+$format2 = "%d %d";
+$format3 = "%d %d %d";
+$arg1 = 111;
+$arg2 = 222;
+$arg3 = 333;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments--\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments--\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments--\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using integer format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments--
+111
+int(3)
+
+-- Calling printf() with two arguments--
+111 222
+int(7)
+
+-- Calling printf() with three arguments--
+111 222 333
+int(11)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - float format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using float format ***\n";
+
+
+// Initialise all required variables
+
+$format = "format";
+$format1 = "%f";
+$format2 = "%f %f";
+$format3 = "%f %f %f";
+
+$format11 = "%F";
+$format22 = "%F %F";
+$format33 = "%F %F %F";
+$arg1 = 11.11;
+$arg2 = 22.22;
+$arg3 = 33.33;
+
+echo "\n-- Calling printf() with no arguments--\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments--\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+$result = printf($format11, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments--\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+$result = printf($format22, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments--\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+$result = printf($format33, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using float format ***
+
+-- Calling printf() with no arguments--
+format
+int(6)
+
+-- Calling printf() with one arguments--
+11.110000
+int(9)
+11.110000
+int(9)
+
+-- Calling printf() with two arguments--
+11.110000 22.220000
+int(19)
+11.110000 22.220000
+int(19)
+
+-- Calling printf() with three arguments--
+11.110000 22.220000 33.330000
+int(29)
+11.110000 22.220000 33.330000
+int(29)
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - bool format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using bool format ***\n";
+
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%b";
+$format2 = "%b %b";
+$format3 = "%b %b %b";
+$arg1 = TRUE;
+$arg2 = FALSE;
+$arg3 = true;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments--\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments--\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments--\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using bool format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments--
+1
+int(1)
+
+-- Calling printf() with two arguments--
+1 0
+int(3)
+
+-- Calling printf() with three arguments--
+1 0 1
+int(5)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - char format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using char format ***\n";
+
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%c";
+$format2 = "%c %c";
+$format3 = "%c %c %c";
+$arg1 = 65;
+$arg2 = 66;
+$arg3 = 67;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using char format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments --
+A
+int(1)
+
+-- Calling printf() with two arguments --
+A B
+int(3)
+
+-- Calling printf() with three arguments --
+A B C
+int(5)
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - exponential format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using exponential format ***\n";
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%e";
+$format2 = "%E %e";
+$format3 = "%e %E %e";
+$arg1 = 1000;
+$arg2 = 2e3;
+$arg3 = +3e3;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one argument --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using exponential format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one argument --
+1.000000e+3
+int(11)
+
+-- Calling printf() with two arguments --
+1.000000E+3 2.000000e+3
+int(23)
+
+-- Calling printf() with three arguments --
+1.000000e+3 2.000000E+3 3.000000e+3
+int(35)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - unsigned format
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE != 4) {
+ die("skip this test is for 32bit platform only");
+}
+?>
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using unsigned format ***\n";
+
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%u";
+$format2 = "%u %u";
+$format3 = "%u %u %u";
+$arg1 = -1111;
+$arg2 = -1234567;
+$arg3 = +2345432;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using unsigned format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments --
+4294966185
+int(10)
+
+-- Calling printf() with two arguments --
+4294966185 4293732729
+int(21)
+
+-- Calling printf() with three arguments --
+4294966185 4293732729 2345432
+int(29)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - octal format
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE != 4) {
+ die("skip this test is for 32bit platform only");
+}
+?>
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using octal format ***\n";
+
+// Initialise all required variables
+$format = "format";
+$format1 = "%o";
+$format2 = "%o %o";
+$format3 = "%o %o %o";
+$arg1 = 021;
+$arg2 = -0347;
+$arg3 = 05678;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using octal format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments --
+21
+int(2)
+
+-- Calling printf() with two arguments --
+21 37777777431
+int(14)
+
+-- Calling printf() with three arguments --
+21 37777777431 567
+int(18)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : basic functionality - hexadecimal format
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : basic functionality - using hexadecimal format ***\n";
+
+// Initialise all required variables
+
+// Initialising different format strings
+$format = "format";
+$format1 = "%x";
+$format2 = "%x %x";
+$format3 = "%x %x %x";
+
+$format11 = "%X";
+$format22 = "%X %X";
+$format33 = "%X %X %X";
+
+$arg1 = 11;
+$arg2 = 132;
+$arg3 = 177;
+
+echo "\n-- Calling printf() with no arguments --\n";
+$result = printf($format);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with one arguments --\n";
+$result = printf($format1, $arg1);
+echo "\n";
+var_dump($result);
+$result = printf($format11, $arg1);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with two arguments --\n";
+$result = printf($format2, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+$result = printf($format22, $arg1, $arg2);
+echo "\n";
+var_dump($result);
+
+echo "\n-- Calling printf() with three arguments --\n";
+$result = printf($format3, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+$result = printf($format33, $arg1, $arg2, $arg3);
+echo "\n";
+var_dump($result);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : basic functionality - using hexadecimal format ***
+
+-- Calling printf() with no arguments --
+format
+int(6)
+
+-- Calling printf() with one arguments --
+b
+int(1)
+B
+int(1)
+
+-- Calling printf() with two arguments --
+b 84
+int(4)
+B 84
+int(4)
+
+-- Calling printf() with three arguments --
+b 84 b1
+int(7)
+B 84 B1
+int(7)
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test printf() function : error conditions
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+echo "*** Testing printf() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing printf() function with Zero arguments --\n";
+var_dump( printf() );
+
+echo "\n-- Testing printf() function with less than expected no. of arguments --\n";
+$format1 = '%s';
+$format2 = '%s%s';
+$format3 = '%s%s%s';
+$arg1 = 'one';
+$arg2 = 'two';
+
+echo "\n-- Call printf with one argument less than expected --\n";
+var_dump( printf($format1) );
+var_dump( printf($format2,$arg1) );
+var_dump( printf($format3,$arg1,$arg2) );
+
+echo "\n-- Call printf with two argument less than expected --\n";
+var_dump( printf($format2) );
+var_dump( printf($format3,$arg1) );
+
+echo "\n-- Call printf with three argument less than expected --\n";
+var_dump( printf($format3) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : error conditions ***
+
+-- Testing printf() function with Zero arguments --
+
+Warning: printf() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+-- Testing printf() function with less than expected no. of arguments --
+
+-- Call printf with one argument less than expected --
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+
+-- Call printf with two argument less than expected --
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+
+-- Call printf with three argument less than expected --
+
+Warning: printf(): Too few arguments in %s on line %d
+bool(false)
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test printf() function : usage variations - unexpected values for format argument
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+/*
+* Testing printf() : with different unexpected values for format argument other than the strings
+*/
+
+echo "*** Testing printf() : with unexpected values for format argument ***\n";
+
+// initialing required variables
+$arg1 = "second arg";
+$arg2 = "third arg";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample
+{
+ public function __toString() {
+ return "Object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+/*10*/ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+/*15*/ NULL,
+ null,
+
+ // boolean data
+/*17*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*21*/ "",
+ '',
+
+ // object data
+/*23*/ new sample(),
+
+ // undefined data
+/*24*/ @$undefined_var,
+
+ // unset data
+/*25*/ @$unset_var,
+
+ // resource data
+/*26*/ $file_handle
+);
+
+// loop through each element of the array for format
+
+$count = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $count --\n";
+
+ // with default argument
+ $result = printf($value);
+ echo "\n";
+ var_dump($result);
+
+ // with two arguments
+ $result = printf($value, $arg1);
+ echo "\n";
+ var_dump($result);
+
+ // with three arguments
+ $result = printf($value, $arg1, $arg2);
+ echo "\n";
+ var_dump($result);
+
+ $count++;
+};
+
+// close the resource
+fclose($file_handle);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : with unexpected values for format argument ***
+
+-- Iteration 1 --
+0
+int(1)
+0
+int(1)
+0
+int(1)
+
+-- Iteration 2 --
+1
+int(1)
+1
+int(1)
+1
+int(1)
+
+-- Iteration 3 --
+12345
+int(5)
+12345
+int(5)
+12345
+int(5)
+
+-- Iteration 4 --
+-2345
+int(5)
+-2345
+int(5)
+-2345
+int(5)
+
+-- Iteration 5 --
+10.5
+int(4)
+10.5
+int(4)
+10.5
+int(4)
+
+-- Iteration 6 --
+-10.5
+int(5)
+-10.5
+int(5)
+-10.5
+int(5)
+
+-- Iteration 7 --
+101234567000
+int(12)
+101234567000
+int(12)
+101234567000
+int(12)
+
+-- Iteration 8 --
+1.07654321E-9
+int(13)
+1.07654321E-9
+int(13)
+1.07654321E-9
+int(13)
+
+-- Iteration 9 --
+0.5
+int(3)
+0.5
+int(3)
+0.5
+int(3)
+
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+Notice: Array to string conversion in %s on line %d
+Array
+int(5)
+
+-- Iteration 15 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 16 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 17 --
+1
+int(1)
+1
+int(1)
+1
+int(1)
+
+-- Iteration 18 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 19 --
+1
+int(1)
+1
+int(1)
+1
+int(1)
+
+-- Iteration 20 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 21 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 22 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 23 --
+Object
+int(6)
+Object
+int(6)
+Object
+int(6)
+
+-- Iteration 24 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 25 --
+
+int(0)
+
+int(0)
+
+int(0)
+
+-- Iteration 26 --
+Resource id #%d
+int(%d)
+Resource id #%d
+int(%d)
+Resource id #%d
+int(%d)
+===DONE===
--- /dev/null
+--TEST--
+Test printf() function : usage variations - with all types of values for arg1 argument
+--FILE--
+<?php
+/* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
+ * Description: Produces output according to format .
+ * Source code: ext/standard/formatted_print.c
+ */
+
+error_reporting(E_ALL & ~E_NOTICE);
+
+echo "*** Testing printf() : with different types of values passed for arg1 argument ***\n";
+
+// initialing required variables
+$format = '%s';
+$arg2 = 'third argument';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample
+{
+ public function __toString() {
+ return "Object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+/*10*/ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+/*15*/ NULL,
+ null,
+
+ // boolean data
+/*17*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*21*/ "",
+ '',
+
+ // string data
+/*23*/ "string",
+ 'string',
+
+ // object data
+/*25*/ new sample(),
+
+ // undefined data
+/*26*/ @$undefined_var,
+
+ // unset data
+/*27*/ @$unset_var,
+
+ // resource data
+/*28*/ $file_handle
+);
+
+// loop through each element of the array for arg1
+
+$count = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $count --\n";
+
+ // with two arguments
+ $result = printf($format, $value);
+ echo "\n";
+ var_dump($result);
+
+ // with three arguments
+ $result = printf($format, $value, $arg2);
+ echo "\n";
+ var_dump($result);
+
+ $count++;
+};
+
+// closing the resource
+fclose($file_handle);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing printf() : with different types of values passed for arg1 argument ***
+
+-- Iteration 1 --
+0
+int(1)
+0
+int(1)
+
+-- Iteration 2 --
+1
+int(1)
+1
+int(1)
+
+-- Iteration 3 --
+12345
+int(5)
+12345
+int(5)
+
+-- Iteration 4 --
+-2345
+int(5)
+-2345
+int(5)
+
+-- Iteration 5 --
+10.5
+int(4)
+10.5
+int(4)
+
+-- Iteration 6 --
+-10.5
+int(5)
+-10.5
+int(5)
+
+-- Iteration 7 --
+101234567000
+int(12)
+101234567000
+int(12)
+
+-- Iteration 8 --
+1.07654321E-9
+int(13)
+1.07654321E-9
+int(13)
+
+-- Iteration 9 --
+0.5
+int(3)
+0.5
+int(3)
+
+-- Iteration 10 --
+Array
+int(5)
+Array
+int(5)
+
+-- Iteration 11 --
+Array
+int(5)
+Array
+int(5)
+
+-- Iteration 12 --
+Array
+int(5)
+Array
+int(5)
+
+-- Iteration 13 --
+Array
+int(5)
+Array
+int(5)
+
+-- Iteration 14 --
+Array
+int(5)
+Array
+int(5)
+
+-- Iteration 15 --
+
+int(0)
+
+int(0)
+
+-- Iteration 16 --
+
+int(0)
+
+int(0)
+
+-- Iteration 17 --
+1
+int(1)
+1
+int(1)
+
+-- Iteration 18 --
+
+int(0)
+
+int(0)
+
+-- Iteration 19 --
+1
+int(1)
+1
+int(1)
+
+-- Iteration 20 --
+
+int(0)
+
+int(0)
+
+-- Iteration 21 --
+
+int(0)
+
+int(0)
+
+-- Iteration 22 --
+
+int(0)
+
+int(0)
+
+-- Iteration 23 --
+string
+int(6)
+string
+int(6)
+
+-- Iteration 24 --
+string
+int(6)
+string
+int(6)
+
+-- Iteration 25 --
+Object
+int(6)
+Object
+int(6)
+
+-- Iteration 26 --
+
+int(0)
+
+int(0)
+
+-- Iteration 27 --
+
+int(0)
+
+int(0)
+
+-- Iteration 28 --
+Resource id #%d
+int(%d)
+Resource id #%d
+int(%d)
+===DONE===
--- /dev/null
+--TEST--
+Test quoted_printable_decode() function : basic functionality
+--FILE--
+<?php
+/* Prototype : string quoted_printable_decode ( string $str )
+ * Description: Convert a quoted-printable string to an 8 bit string
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing quoted_printable_decode() : basic functionality ***\n";
+
+$str = "=FAwow-factor=C1=d0=D5=DD=C5=CE=CE=D9=C5=0A=
+=20=D4=cf=D2=C7=CF=D7=D9=C5=
+=20=
+=D0=
+=D2=CF=C5=CB=D4=D9";
+
+var_dump(bin2hex(quoted_printable_decode($str)));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing quoted_printable_decode() : basic functionality ***
+string(76) "fa776f772d666163746f72c1d0d5ddc5ceced9c50a20d4cfd2c7cfd7d9c520d0d2cfc5cbd4d9"
+===DONE===
--- /dev/null
+--TEST--
+Test quoted_printable_decode() function : error conditions
+--FILE--
+<?php
+/* Prototype : string quoted_printable_decode ( string $str )
+ * Description: Convert a quoted-printable string to an 8 bit string
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing quoted_printable_decode() : error conditions ***\n";
+
+echo "\n-- Testing quoted_printable_decode() function with no arguments --\n";
+var_dump( quoted_printable_decode() );
+
+echo "\n-- Testing quoted_printable_decode() function with more than expected no. of arguments --\n";
+$str = b"=FAwow-factor=C1=d0=D5=DD=C5=CE=CE=D9=C5=0A=
+=20=D4=cf=D2=C7=CF=D7=D9=C5=
+=20=
+=D0=
+=D2=CF=C5=CB=D4=D9";
+$extra_arg = 10;
+var_dump( quoted_printable_decode($str, $extra_arg) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing quoted_printable_decode() : error conditions ***
+
+-- Testing quoted_printable_decode() function with no arguments --
+
+Warning: quoted_printable_decode() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing quoted_printable_decode() function with more than expected no. of arguments --
+
+Warning: quoted_printable_decode() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
--- /dev/null
+--TEST--
+Test quoted_printable_decode() function : usage variations - unexpected values for 'str' argument
+--FILE--
+<?php
+/* Prototype : string quoted_printable_decode ( string $str )
+ * Description: Convert a quoted-printable string to an 8 bit string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+* Testing quoted_printable_decode() : with different unexpected values for format argument other than the strings
+*/
+
+echo "*** Testing quoted_printable_decode() : with unexpected values for 'str' argument ***\n";
+
+// initialing required variables
+$arg1 = "second arg";
+$arg2 = "third arg";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample
+{
+ public function __toString() {
+ return "Object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+/*10*/ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+/*15*/ NULL,
+ null,
+
+ // boolean data
+/*17*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*21*/ "",
+ '',
+
+ // object data
+/*23*/ new sample(),
+
+ // undefined data
+/*24*/ @$undefined_var,
+
+ // unset data
+/*25*/ @$unset_var,
+
+ // resource data
+/*26*/ $file_handle
+);
+
+// loop through each element of the array for 'str'
+
+$count = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $count --\n";
+ var_dump(bin2hex(quoted_printable_decode($value)));
+ $count++;
+};
+
+// close the resource
+fclose($file_handle);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing quoted_printable_decode() : with unexpected values for 'str' argument ***
+
+-- Iteration 1 --
+string(2) "30"
+
+-- Iteration 2 --
+string(2) "31"
+
+-- Iteration 3 --
+string(10) "3132333435"
+
+-- Iteration 4 --
+string(10) "2d32333435"
+
+-- Iteration 5 --
+string(8) "31302e35"
+
+-- Iteration 6 --
+string(10) "2d31302e35"
+
+-- Iteration 7 --
+string(24) "313031323334353637303030"
+
+-- Iteration 8 --
+string(26) "312e3037363534333231452d39"
+
+-- Iteration 9 --
+string(6) "302e35"
+
+-- Iteration 10 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, array given in %s on line %d
+string(0) ""
+
+-- Iteration 11 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, array given in %s on line %d
+string(0) ""
+
+-- Iteration 12 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, array given in %s on line %d
+string(0) ""
+
+-- Iteration 13 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, array given in %s on line %d
+string(0) ""
+
+-- Iteration 14 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, array given in %s on line %d
+string(0) ""
+
+-- Iteration 15 --
+string(0) ""
+
+-- Iteration 16 --
+string(0) ""
+
+-- Iteration 17 --
+string(2) "31"
+
+-- Iteration 18 --
+string(0) ""
+
+-- Iteration 19 --
+string(2) "31"
+
+-- Iteration 20 --
+string(0) ""
+
+-- Iteration 21 --
+string(0) ""
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(12) "4f626a656374"
+
+-- Iteration 24 --
+string(0) ""
+
+-- Iteration 25 --
+string(0) ""
+
+-- Iteration 26 --
+
+Warning: quoted_printable_decode() expects parameter 1 to be string, resource given in %s on line %d
+string(0) ""
+===DONE===
--- /dev/null
+--TEST--
+Test quotemeta() function : basic functionality
+--FILE--
+<?php
+
+/* Prototype : string quotemeta ( string $str )
+ * Description: Quote meta characters
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing quotemeta() : basic functionality ***\n";
+
+var_dump(quotemeta("Hello how are you ?"));
+var_dump(quotemeta("(100 + 50) * 10"));
+var_dump(quotemeta("\+*?[^]($)"));
+?>
+===DONE===
+--EXPECTF--
+*** Testing quotemeta() : basic functionality ***
+string(20) "Hello how are you \?"
+string(19) "\(100 \+ 50\) \* 10"
+string(20) "\\\+\*\?\[\^\]\(\$\)"
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test quotemeta() function : error conditions
+--FILE--
+<?php
+
+/* Prototype : string quotemeta ( string $str )
+ * Description: Quote meta characters
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing quotemeta() : error conditions ***\n";
+
+echo "\n-- Testing quotemeta() function with no arguments --\n";
+var_dump( quotemeta());
+
+echo "\n-- Testing quotemeta() function with more than expected no. of arguments --\n";
+$extra_arg = 10;
+var_dump(quotemeta("How are you ?", $extra_arg));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing quotemeta() : error conditions ***
+
+-- Testing quotemeta() function with no arguments --
+
+Warning: quotemeta() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing quotemeta() function with more than expected no. of arguments --
+
+Warning: quotemeta() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test rtrim() function : basic functionality
+--FILE--
+<?php
+
+/* Prototype : string rtrim ( string $str [, string $charlist ] )
+ * Description: Strip whitespace (or other characters) from the end of a string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing rtrim() : basic functionality ***\n";
+
+$text = "---These are a few words--- \t\r\n\0\x0B ";
+$hello = "!===Hello World===!";
+$alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+$binary = "Example string\x0A\x0D";
+
+
+
+echo "\n-- Trim string with all white space characters --\n";
+var_dump(rtrim($text));
+
+echo "\n-- Trim non-whitespace from a string --\n";
+var_dump(rtrim($hello, "=!"));
+
+echo "\n-- Trim some non-white space characters from a string --\n";
+var_dump(rtrim($hello, "!dlWro="));
+
+echo "\n-- Trim some non-white space characters from a string using a character range --\n";
+var_dump(rtrim($alpha, "A..Z"));
+
+echo "\n-- Trim the ASCII control characters at the beginning of a string --\n";
+var_dump(rtrim($binary, "\x00..\x1F"));
+
+?>
+===DONE===
+--EXPECT--
+*** Testing rtrim() : basic functionality ***
+
+-- Trim string with all white space characters --
+string(27) "---These are a few words---"
+
+-- Trim non-whitespace from a string --
+string(15) "!===Hello World"
+
+-- Trim some non-white space characters from a string --
+string(10) "!===Hello "
+
+-- Trim some non-white space characters from a string using a character range --
+string(10) "0123456789"
+
+-- Trim the ASCII control characters at the beginning of a string --
+string(14) "Example string"
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Test rtrim() function : error conditions
+--FILE--
+<?php
+
+/* Prototype : string rtrim ( string $str [, string $charlist ] )
+ * Description: Strip whitespace (or other characters) from the end of a string.
+ * Source code: ext/standard/string.c
+*/
+
+
+echo "*** Testing rtrim() : error conditions ***\n";
+
+echo "\n-- Testing rtrim() function with no arguments --\n";
+var_dump( rtrim() );
+
+echo "\n-- Testing rtrim() function with more than expected no. of arguments --\n";
+$extra_arg = 10;
+var_dump( rtrim("Hello World", "Heo", $extra_arg) );
+
+
+$hello = " Hello World\n";
+echo "\n-- Test rtrim function with various invalid charlists\n";
+var_dump(rtrim($hello, "..a"));
+var_dump(rtrim($hello, "a.."));
+var_dump(rtrim($hello, "z..a"));
+var_dump(rtrim($hello, "a..b..c"));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing rtrim() : error conditions ***
+
+-- Testing rtrim() function with no arguments --
+
+Warning: rtrim() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing rtrim() function with more than expected no. of arguments --
+
+Warning: rtrim() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Test rtrim function with various invalid charlists
+
+Warning: rtrim(): Invalid '..'-range, no character to the left of '..' in %s on line %d
+string(14) " Hello World
+"
+
+Warning: rtrim(): Invalid '..'-range, no character to the right of '..' in %s on line %d
+string(14) " Hello World
+"
+
+Warning: rtrim(): Invalid '..'-range, '..'-range needs to be incrementing in %s on line %d
+string(14) " Hello World
+"
+
+Warning: rtrim(): Invalid '..'-range in %s on line %d
+string(14) " Hello World
+"
+===DONE===
--- /dev/null
+--TEST--
+Test rtrim() function : usage variations - test values for $str argument
+--FILE--
+<?php
+
+/* Prototype : string rtrim ( string $str [, string $charlist ] )
+ * Description: Strip whitespace (or other characters) from the end of a string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing rtrim() function: with unexpected inputs for 'str' argument ***\n";
+
+//get an unset variable
+$unset_var = ' !--string_val--! ';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return " !---sample object---! ";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $input
+$inputs = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ 255,
+ 256,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*7*/ 10.5,
+ -20.5,
+ 10.1234567e10,
+
+ // array values
+/*10*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*13*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null values
+/*17*/ NULL,
+ null,
+
+ // objects
+/*19*/ new sample(),
+
+ // resource
+/*20*/ $file_handle,
+
+ // undefined variable
+/*21*/ @$undefined_var,
+
+ // unset variable
+/*22*/ @$unset_var
+);
+
+// loop through with each element of the $inputs array to test rtrim() function
+$count = 1;
+foreach($inputs as $input) {
+ echo "-- Iteration $count --\n";
+ // strip white space and any "minus" signs
+ var_dump( rtrim($input, " !-") );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing rtrim() function: with unexpected inputs for 'str' argument ***
+-- Iteration 1 --
+string(1) "0"
+-- Iteration 2 --
+string(1) "1"
+-- Iteration 3 --
+string(3) "255"
+-- Iteration 4 --
+string(3) "256"
+-- Iteration 5 --
+string(10) "2147483647"
+-- Iteration 6 --
+string(11) "-2147483648"
+-- Iteration 7 --
+string(4) "10.5"
+-- Iteration 8 --
+string(5) "-20.5"
+-- Iteration 9 --
+string(12) "101234567000"
+-- Iteration 10 --
+
+Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 13 --
+string(1) "1"
+-- Iteration 14 --
+string(0) ""
+-- Iteration 15 --
+string(1) "1"
+-- Iteration 16 --
+string(0) ""
+-- Iteration 17 --
+string(0) ""
+-- Iteration 18 --
+string(0) ""
+-- Iteration 19 --
+string(19) " !---sample object"
+-- Iteration 20 --
+
+Warning: rtrim() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+-- Iteration 21 --
+string(0) ""
+-- Iteration 22 --
+string(0) ""
+===DONE===
--- /dev/null
+--TEST--
+Test rtrim() function : usage variations - test values for $charlist argument
+--FILE--
+<?php
+
+/* Prototype : string rtrim ( string $str [, string $charlist ] )
+ * Description: Strip whitespace (or other characters) from the end of a string.
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing rtrim() function: with unexpected inputs for 'charlist' argument ***\n";
+
+//get an unset variable
+$unset_var = ' string_val ';
+unset($unset_var);
+
+//defining a class
+class sample {
+ public function __toString() {
+ return " sample object ";
+ }
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $input
+$inputs = array (
+
+ // integer values
+/*1*/ 0,
+ 1,
+ 255,
+ 256,
+ 2147483647,
+ -2147483648,
+
+ // float values
+/*7*/ 10.5,
+ -20.5,
+ 10.1234567e10,
+
+ // array values
+/*10*/ array(),
+ array(0),
+ array(1, 2),
+
+ // boolean values
+/*13*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // null values
+/*17*/ NULL,
+ null,
+
+ // objects
+/*19*/ new sample(),
+
+ // resource
+/*20*/ $file_handle,
+
+ // undefined variable
+/*21*/ @$undefined_var,
+
+ // unset variable
+/*22*/ @$unset_var
+);
+
+// loop through with each element of the $inputs array to test rtrim() function
+$count = 1;
+foreach($inputs as $charlist) {
+ echo "-- Iteration $count --\n";
+ // strip white space and any "minus" signs
+ var_dump( rtrim("!---Hello World---!", $charlist) );
+ $count ++;
+}
+
+fclose($file_handle); //closing the file handle
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing rtrim() function: with unexpected inputs for 'charlist' argument ***
+-- Iteration 1 --
+string(19) "!---Hello World---!"
+-- Iteration 2 --
+string(19) "!---Hello World---!"
+-- Iteration 3 --
+string(19) "!---Hello World---!"
+-- Iteration 4 --
+string(19) "!---Hello World---!"
+-- Iteration 5 --
+string(19) "!---Hello World---!"
+-- Iteration 6 --
+string(19) "!---Hello World---!"
+-- Iteration 7 --
+string(19) "!---Hello World---!"
+-- Iteration 8 --
+string(19) "!---Hello World---!"
+-- Iteration 9 --
+string(19) "!---Hello World---!"
+-- Iteration 10 --
+
+Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
+NULL
+-- Iteration 13 --
+string(19) "!---Hello World---!"
+-- Iteration 14 --
+string(19) "!---Hello World---!"
+-- Iteration 15 --
+string(19) "!---Hello World---!"
+-- Iteration 16 --
+string(19) "!---Hello World---!"
+-- Iteration 17 --
+string(19) "!---Hello World---!"
+-- Iteration 18 --
+string(19) "!---Hello World---!"
+-- Iteration 19 --
+string(19) "!---Hello World---!"
+-- Iteration 20 --
+
+Warning: rtrim() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+-- Iteration 21 --
+string(19) "!---Hello World---!"
+-- Iteration 22 --
+string(19) "!---Hello World---!"
+===DONE===