--- /dev/null
+--TEST--
+Test str_split() function : basic functionality
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing str_split() : basic functionality ***\n";
+
+// Initialise all required variables
+$str = 'This is basic testcase';
+$split_length = 5;
+
+// Calling str_split() with all possible arguments
+echo "-- With all possible arguments --\n";
+var_dump( str_split($str,$split_length) );
+
+// Calling str_split() with default arguments
+echo "-- With split_length as default argument --\n";
+var_dump( str_split($str) );
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : basic functionality ***
+-- With all possible arguments --
+array(5) {
+ [0]=>
+ string(5) "This "
+ [1]=>
+ string(5) "is ba"
+ [2]=>
+ string(5) "sic t"
+ [3]=>
+ string(5) "estca"
+ [4]=>
+ string(2) "se"
+}
+-- With split_length as default argument --
+array(22) {
+ [0]=>
+ string(1) "T"
+ [1]=>
+ string(1) "h"
+ [2]=>
+ string(1) "i"
+ [3]=>
+ string(1) "s"
+ [4]=>
+ string(1) " "
+ [5]=>
+ string(1) "i"
+ [6]=>
+ string(1) "s"
+ [7]=>
+ string(1) " "
+ [8]=>
+ string(1) "b"
+ [9]=>
+ string(1) "a"
+ [10]=>
+ string(1) "s"
+ [11]=>
+ string(1) "i"
+ [12]=>
+ string(1) "c"
+ [13]=>
+ string(1) " "
+ [14]=>
+ string(1) "t"
+ [15]=>
+ string(1) "e"
+ [16]=>
+ string(1) "s"
+ [17]=>
+ string(1) "t"
+ [18]=>
+ string(1) "c"
+ [19]=>
+ string(1) "a"
+ [20]=>
+ string(1) "s"
+ [21]=>
+ string(1) "e"
+}
+Done
--- /dev/null
+--TEST--
+Test str_split() function : error conditions
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing str_split() : error conditions ***\n";
+
+// Zero arguments
+echo "-- Testing str_split() function with Zero arguments --\n";
+var_dump( str_split() );
+
+//Test str_split with one more than the expected number of arguments
+echo "-- Testing str_split() function with more than expected no. of arguments --\n";
+$str = 'This is error testcase';
+$split_length = 4;
+$extra_arg = 10;
+var_dump( str_split( $str, $split_length, $extra_arg) );
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : error conditions ***
+-- Testing str_split() function with Zero arguments --
+
+Warning: str_split() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+-- Testing str_split() function with more than expected no. of arguments --
+
+Warning: str_split() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+Done
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - unexpected values for 'str' argument
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing str_split() : unexpected values for 'str' ***\n";
+
+// Initialise function arguments
+$split_length = 3;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+//defining class for object variable
+class MyClass
+{
+ public function __toString()
+ {
+ return "object";
+ }
+}
+
+//resource variable
+$fp = fopen(__FILE__, 'r');
+
+//different values for 'str' argument
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.5e10,
+ 10.6E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+
+ //resource data
+ $fp
+);
+
+// loop through each element of $values for 'str' argument
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count+1)." --\n";
+ var_dump( str_split($values[$count], $split_length) );
+}
+
+//closing resource
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing str_split() : unexpected values for 'str' ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(1) "0"
+}
+-- Iteration 2 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 3 --
+array(2) {
+ [0]=>
+ string(3) "123"
+ [1]=>
+ string(2) "45"
+}
+-- Iteration 4 --
+array(2) {
+ [0]=>
+ string(3) "-23"
+ [1]=>
+ string(2) "45"
+}
+-- Iteration 5 --
+array(2) {
+ [0]=>
+ string(3) "10."
+ [1]=>
+ string(1) "5"
+}
+-- Iteration 6 --
+array(2) {
+ [0]=>
+ string(3) "-10"
+ [1]=>
+ string(2) ".5"
+}
+-- Iteration 7 --
+array(4) {
+ [0]=>
+ string(3) "105"
+ [1]=>
+ string(3) "000"
+ [2]=>
+ string(3) "000"
+ [3]=>
+ string(3) "000"
+}
+-- Iteration 8 --
+array(3) {
+ [0]=>
+ string(3) "1.0"
+ [1]=>
+ string(3) "6E-"
+ [2]=>
+ string(1) "9"
+}
+-- Iteration 9 --
+array(1) {
+ [0]=>
+ string(3) "0.5"
+}
+-- Iteration 10 --
+
+Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 13 --
+
+Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 14 --
+
+Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
+NULL
+-- Iteration 15 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 16 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 17 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 18 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 19 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+-- Iteration 20 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 21 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 22 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 23 --
+array(2) {
+ [0]=>
+ string(3) "obj"
+ [1]=>
+ string(3) "ect"
+}
+-- Iteration 24 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 25 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 26 --
+
+Warning: str_split() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - unexpected values for 'split_length' argument
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing str_split() : unexpected values for 'split_length' ***\n";
+
+// Initialise function arguments
+$str = 'variation2:split_length';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+//defining class for object variable
+class MyClass
+{
+ public function __toString()
+ {
+ return "object";
+ }
+}
+
+//resource variable
+$fp = fopen(__FILE__, 'r');
+
+//different values for 'split_length'
+$values = array(
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.6E10,
+ 10.6E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // string data
+ "string",
+ 'string',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+
+ //resource data
+ $fp
+);
+
+// loop through each element of $values for 'split_length'
+for($count = 0; $count < count($values); $count++) {
+ echo "--Iteration ".($count+1)." --\n";
+ var_dump( str_split($str, $values[$count]) );
+}
+
+//closing resource
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing str_split() : unexpected values for 'split_length' ***
+--Iteration 1 --
+array(3) {
+ [0]=>
+ string(10) "variation2"
+ [1]=>
+ string(10) ":split_len"
+ [2]=>
+ string(3) "gth"
+}
+--Iteration 2 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 3 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 4 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 5 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 6 --
+
+Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
+NULL
+--Iteration 7 --
+
+Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
+NULL
+--Iteration 8 --
+
+Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
+NULL
+--Iteration 9 --
+
+Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
+NULL
+--Iteration 10 --
+
+Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
+NULL
+--Iteration 11 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 12 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 13 --
+array(23) {
+ [0]=>
+ string(1) "v"
+ [1]=>
+ string(1) "a"
+ [2]=>
+ string(1) "r"
+ [3]=>
+ string(1) "i"
+ [4]=>
+ string(1) "a"
+ [5]=>
+ string(1) "t"
+ [6]=>
+ string(1) "i"
+ [7]=>
+ string(1) "o"
+ [8]=>
+ string(1) "n"
+ [9]=>
+ string(1) "2"
+ [10]=>
+ string(1) ":"
+ [11]=>
+ string(1) "s"
+ [12]=>
+ string(1) "p"
+ [13]=>
+ string(1) "l"
+ [14]=>
+ string(1) "i"
+ [15]=>
+ string(1) "t"
+ [16]=>
+ string(1) "_"
+ [17]=>
+ string(1) "l"
+ [18]=>
+ string(1) "e"
+ [19]=>
+ string(1) "n"
+ [20]=>
+ string(1) "g"
+ [21]=>
+ string(1) "t"
+ [22]=>
+ string(1) "h"
+}
+--Iteration 14 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 15 --
+array(23) {
+ [0]=>
+ string(1) "v"
+ [1]=>
+ string(1) "a"
+ [2]=>
+ string(1) "r"
+ [3]=>
+ string(1) "i"
+ [4]=>
+ string(1) "a"
+ [5]=>
+ string(1) "t"
+ [6]=>
+ string(1) "i"
+ [7]=>
+ string(1) "o"
+ [8]=>
+ string(1) "n"
+ [9]=>
+ string(1) "2"
+ [10]=>
+ string(1) ":"
+ [11]=>
+ string(1) "s"
+ [12]=>
+ string(1) "p"
+ [13]=>
+ string(1) "l"
+ [14]=>
+ string(1) "i"
+ [15]=>
+ string(1) "t"
+ [16]=>
+ string(1) "_"
+ [17]=>
+ string(1) "l"
+ [18]=>
+ string(1) "e"
+ [19]=>
+ string(1) "n"
+ [20]=>
+ string(1) "g"
+ [21]=>
+ string(1) "t"
+ [22]=>
+ string(1) "h"
+}
+--Iteration 16 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 17 --
+
+Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
+NULL
+--Iteration 18 --
+
+Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
+NULL
+--Iteration 19 --
+
+Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
+NULL
+--Iteration 20 --
+
+Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
+NULL
+--Iteration 21 --
+
+Warning: str_split() expects parameter 2 to be long, object given in %s on line %d
+NULL
+--Iteration 22 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 23 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+--Iteration 24 --
+
+Warning: str_split() expects parameter 2 to be long, resource given in %s on line %d
+NULL
+Done
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - different single quoted strings for 'str' argument
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+/*
+* passing different single quoted strings as 'str' argument to str_split()
+* split_length is set to 5
+*/
+
+echo "*** Testing str_split() : single quoted strings for 'str' ***\n";
+
+//Initialize variables
+$split_length = 5;
+
+// different values for 'str'
+$values = array(
+ '', //empty
+ ' ', //space
+ '1234', //with only numbers
+ 'simple string', //regular string
+ 'It\'s string with quote', //string containing single quote
+ 'string\tcontains\rwhite space\nchars',
+ 'containing @ # $ % ^ & chars',
+ 'with 1234 numbers',
+ 'with \0 and ".chr(0)."null chars', //for binary safe
+ 'with multiple space char',
+ 'Testing invalid \k and \m escape char',
+ 'to check with \\n and \\t' //ignoring \n and \t results
+);
+
+//loop through each element of $values for 'str' argument
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count+1)." --\n";
+ var_dump( str_split($values[$count], $split_length) );
+}
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : single quoted strings for 'str' ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 2 --
+array(1) {
+ [0]=>
+ string(1) " "
+}
+-- Iteration 3 --
+array(1) {
+ [0]=>
+ string(4) "1234"
+}
+-- Iteration 4 --
+array(3) {
+ [0]=>
+ string(5) "simpl"
+ [1]=>
+ string(5) "e str"
+ [2]=>
+ string(3) "ing"
+}
+-- Iteration 5 --
+array(5) {
+ [0]=>
+ string(5) "It's "
+ [1]=>
+ string(5) "strin"
+ [2]=>
+ string(5) "g wit"
+ [3]=>
+ string(5) "h quo"
+ [4]=>
+ string(2) "te"
+}
+-- Iteration 6 --
+array(8) {
+ [0]=>
+ string(5) "strin"
+ [1]=>
+ string(5) "g\tco"
+ [2]=>
+ string(5) "ntain"
+ [3]=>
+ string(5) "s\rwh"
+ [4]=>
+ string(5) "ite s"
+ [5]=>
+ string(5) "pace\"
+ [6]=>
+ string(5) "nchar"
+ [7]=>
+ string(1) "s"
+}
+-- Iteration 7 --
+array(6) {
+ [0]=>
+ string(5) "conta"
+ [1]=>
+ string(5) "ining"
+ [2]=>
+ string(5) " @ # "
+ [3]=>
+ string(5) "$ % ^"
+ [4]=>
+ string(5) " & ch"
+ [5]=>
+ string(3) "ars"
+}
+-- Iteration 8 --
+array(4) {
+ [0]=>
+ string(5) "with "
+ [1]=>
+ string(5) "1234 "
+ [2]=>
+ string(5) "numbe"
+ [3]=>
+ string(2) "rs"
+}
+-- Iteration 9 --
+array(7) {
+ [0]=>
+ string(5) "with "
+ [1]=>
+ string(5) "\0 an"
+ [2]=>
+ string(5) "d ".c"
+ [3]=>
+ string(5) "hr(0)"
+ [4]=>
+ string(5) "."nul"
+ [5]=>
+ string(5) "l cha"
+ [6]=>
+ string(2) "rs"
+}
+-- Iteration 10 --
+array(7) {
+ [0]=>
+ string(5) "with "
+ [1]=>
+ string(5) " mu"
+ [2]=>
+ string(5) "ltipl"
+ [3]=>
+ string(5) "e "
+ [4]=>
+ string(5) " spac"
+ [5]=>
+ string(5) "e cha"
+ [6]=>
+ string(1) "r"
+}
+-- Iteration 11 --
+array(8) {
+ [0]=>
+ string(5) "Testi"
+ [1]=>
+ string(5) "ng in"
+ [2]=>
+ string(5) "valid"
+ [3]=>
+ string(5) " \k a"
+ [4]=>
+ string(5) "nd \m"
+ [5]=>
+ string(5) " esca"
+ [6]=>
+ string(5) "pe ch"
+ [7]=>
+ string(2) "ar"
+}
+-- Iteration 12 --
+array(5) {
+ [0]=>
+ string(5) "to ch"
+ [1]=>
+ string(5) "eck w"
+ [2]=>
+ string(5) "ith \"
+ [3]=>
+ string(5) "n and"
+ [4]=>
+ string(3) " \t"
+}
+Done
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - different heredoc strings as 'str' argument
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length] )
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+/*
+* Passing different heredoc strings as 'str' argument to the str_split()
+* with 'split_length' 10
+*/
+
+echo "*** Testing str_split() : heredoc strings as 'str' argument ***\n";
+
+// Initializing required variables
+$split_length = 10;
+
+// Null heredoc string
+$heredoc_null = <<<EOT1
+EOT1;
+
+// heredoc string with single character
+$heredoc_char = <<<EOT2
+a
+EOT2;
+
+// simple heredoc string
+$heredoc_str = <<<EOT3
+This is simple heredoc string
+EOT3;
+
+// heredoc with special characters
+$heredoc_spchar = <<<EOT4
+This checks heredoc with $, %, &, chars
+EOT4;
+
+// blank heredoc string
+$heredoc_blank = <<<EOT5
+
+EOT5;
+
+// heredoc with different white space characters
+$heredoc_escchar = <<<EOT6
+This checks\t str_split()\nEscape\rchars
+EOT6;
+
+// heredoc with multiline
+$heredoc_multiline= <<<EOT7
+This is to check str_split
+function with multiline
+heredoc
+EOT7;
+
+// heredoc with quotes and slashes
+$heredoc_quote_slash = <<<EOT8
+"To check " in heredoc"
+I'm sure it'll work also with \
+which is single slash
+EOT8;
+
+//different heredoc strings for 'str'
+$heredoc_array = array(
+ $heredoc_null,
+ $heredoc_blank,
+ $heredoc_char,
+ $heredoc_str,
+ $heredoc_multiline,
+ $heredoc_spchar,
+ $heredoc_escchar,
+ $heredoc_quote_slash
+);
+
+
+// loop through each element of the 'heredoc_array' for 'str'
+$count = 0;
+foreach($heredoc_array as $str) {
+ echo "-- Iteration ".($count+1). " --\n";
+ var_dump( str_split($str, $split_length) );
+ $count++;
+};
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : heredoc strings as 'str' argument ***
+-- Iteration 1 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 2 --
+array(1) {
+ [0]=>
+ string(0) ""
+}
+-- Iteration 3 --
+array(1) {
+ [0]=>
+ string(1) "a"
+}
+-- Iteration 4 --
+array(3) {
+ [0]=>
+ string(10) "This is si"
+ [1]=>
+ string(10) "mple hered"
+ [2]=>
+ string(9) "oc string"
+}
+-- Iteration 5 --
+array(6) {
+ [0]=>
+ string(10) "This is to"
+ [1]=>
+ string(10) " check str"
+ [2]=>
+ string(10) "_split
+fun"
+ [3]=>
+ string(10) "ction with"
+ [4]=>
+ string(10) " multiline"
+ [5]=>
+ string(8) "
+heredoc"
+}
+-- Iteration 6 --
+array(4) {
+ [0]=>
+ string(10) "This check"
+ [1]=>
+ string(10) "s heredoc "
+ [2]=>
+ string(10) "with $, %,"
+ [3]=>
+ string(9) " &, chars"
+}
+-- Iteration 7 --
+array(4) {
+ [0]=>
+ string(10) "This check"
+ [1]=>
+ string(10) "s str_spl"
+ [2]=>
+ string(10) "it()
+Escap"
+ [3]=>
+ string(7) "e
+chars"
+}
+-- Iteration 8 --
+array(8) {
+ [0]=>
+ string(10) ""To check "
+ [1]=>
+ string(10) "" in hered"
+ [2]=>
+ string(10) "oc"
+I'm su"
+ [3]=>
+ string(10) "re it'll w"
+ [4]=>
+ string(10) "ork also w"
+ [5]=>
+ string(10) "ith \
+whic"
+ [6]=>
+ string(10) "h is singl"
+ [7]=>
+ string(7) "e slash"
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - different integer values for 'split_length' argument
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+/*
+* passing different integer values for 'split_length' argument to str_split()
+*/
+
+echo "*** Testing str_split() : different intger values for 'split_length' ***\n";
+//Initialise variables
+$str = 'This is a string with 123 & escape char \t';
+
+//different values for 'split_length'
+$values = array (
+ 0,
+ 1,
+ -123, //negative integer
+ 0234, //octal number
+ 0x1A, //hexadecimal number
+ 2147483647, //max positive integer number
+ 2147483648, //max positive integer+1
+ -2147483648, //min negative integer
+);
+
+//loop through each element of $values for 'split_length'
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count + 1)." --\n";
+ var_dump( str_split($str, $values[$count]) );
+}
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : different intger values for 'split_length' ***
+-- Iteration 1 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 2 --
+array(42) {
+ [0]=>
+ string(1) "T"
+ [1]=>
+ string(1) "h"
+ [2]=>
+ string(1) "i"
+ [3]=>
+ string(1) "s"
+ [4]=>
+ string(1) " "
+ [5]=>
+ string(1) "i"
+ [6]=>
+ string(1) "s"
+ [7]=>
+ string(1) " "
+ [8]=>
+ string(1) "a"
+ [9]=>
+ string(1) " "
+ [10]=>
+ string(1) "s"
+ [11]=>
+ string(1) "t"
+ [12]=>
+ string(1) "r"
+ [13]=>
+ string(1) "i"
+ [14]=>
+ string(1) "n"
+ [15]=>
+ string(1) "g"
+ [16]=>
+ string(1) " "
+ [17]=>
+ string(1) "w"
+ [18]=>
+ string(1) "i"
+ [19]=>
+ string(1) "t"
+ [20]=>
+ string(1) "h"
+ [21]=>
+ string(1) " "
+ [22]=>
+ string(1) "1"
+ [23]=>
+ string(1) "2"
+ [24]=>
+ string(1) "3"
+ [25]=>
+ string(1) " "
+ [26]=>
+ string(1) "&"
+ [27]=>
+ string(1) " "
+ [28]=>
+ string(1) "e"
+ [29]=>
+ string(1) "s"
+ [30]=>
+ string(1) "c"
+ [31]=>
+ string(1) "a"
+ [32]=>
+ string(1) "p"
+ [33]=>
+ string(1) "e"
+ [34]=>
+ string(1) " "
+ [35]=>
+ string(1) "c"
+ [36]=>
+ string(1) "h"
+ [37]=>
+ string(1) "a"
+ [38]=>
+ string(1) "r"
+ [39]=>
+ string(1) " "
+ [40]=>
+ string(1) "\"
+ [41]=>
+ string(1) "t"
+}
+-- Iteration 3 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 4 --
+array(1) {
+ [0]=>
+ string(42) "This is a string with 123 & escape char \t"
+}
+-- Iteration 5 --
+array(2) {
+ [0]=>
+ string(26) "This is a string with 123 "
+ [1]=>
+ string(16) "& escape char \t"
+}
+-- Iteration 6 --
+array(1) {
+ [0]=>
+ string(42) "This is a string with 123 & escape char \t"
+}
+-- Iteration 7 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test str_split() function : usage variations - different integer values for 'split_length' with heredoc 'str'
+--FILE--
+<?php
+/* Prototype : array str_split(string $str [, int $split_length])
+ * Description: Convert a string to an array. If split_length is
+ specified, break the string down into chunks each
+ split_length characters long.
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+/*
+* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
+*/
+
+echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n";
+//Initialise variables
+$str = <<<EOT
+string with 123,escape char \t.
+EOT;
+
+//different values for 'split_length'
+$values = array (
+ 0,
+ 1,
+ -123, //negative integer
+ 0234, //octal number
+ 0x1A, //hexadecimal number
+ 2147483647, //max positive integer number
+ 2147483648, //max positive integer+1
+ -2147483648, //min negative integer
+);
+
+//loop through each element of $values for 'split_length'
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count + 1)." --\n";
+ var_dump( str_split($str, $values[$count]) );
+}
+echo "Done"
+?>
+--EXPECTF--
+*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
+-- Iteration 1 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 2 --
+array(30) {
+ [0]=>
+ string(1) "s"
+ [1]=>
+ string(1) "t"
+ [2]=>
+ string(1) "r"
+ [3]=>
+ string(1) "i"
+ [4]=>
+ string(1) "n"
+ [5]=>
+ string(1) "g"
+ [6]=>
+ string(1) " "
+ [7]=>
+ string(1) "w"
+ [8]=>
+ string(1) "i"
+ [9]=>
+ string(1) "t"
+ [10]=>
+ string(1) "h"
+ [11]=>
+ string(1) " "
+ [12]=>
+ string(1) "1"
+ [13]=>
+ string(1) "2"
+ [14]=>
+ string(1) "3"
+ [15]=>
+ string(1) ","
+ [16]=>
+ string(1) "e"
+ [17]=>
+ string(1) "s"
+ [18]=>
+ string(1) "c"
+ [19]=>
+ string(1) "a"
+ [20]=>
+ string(1) "p"
+ [21]=>
+ string(1) "e"
+ [22]=>
+ string(1) " "
+ [23]=>
+ string(1) "c"
+ [24]=>
+ string(1) "h"
+ [25]=>
+ string(1) "a"
+ [26]=>
+ string(1) "r"
+ [27]=>
+ string(1) " "
+ [28]=>
+ string(1) " "
+ [29]=>
+ string(1) "."
+}
+-- Iteration 3 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 4 --
+array(1) {
+ [0]=>
+ string(30) "string with 123,escape char ."
+}
+-- Iteration 5 --
+array(2) {
+ [0]=>
+ string(26) "string with 123,escape cha"
+ [1]=>
+ string(4) "r ."
+}
+-- Iteration 6 --
+array(1) {
+ [0]=>
+ string(30) "string with 123,escape char ."
+}
+-- Iteration 7 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
+bool(false)
+Done