1--TEST--
2Test chunk_split() function : usage variations - different integer values for 'chunklen' with heredoc string as 'str'(Bug#42796)
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--FILE--
8<?php
9/*
10* passing different integer values for 'chunklen' and heredoc string for 'str' to chunk_split()
11*/
12
13echo "*** Testing chunk_split() : different 'chunklen' with heredoc 'str' ***\n";
14
15
16// Initializing required variables
17//heredoc string as str
18$heredoc_str = <<<EOT
19This's heredoc string with \t and \n white space char.
20It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
21chunk_split()
22EOT;
23
24$ending = ':::';
25
26// different values for 'chunklen'
27$values = array (
28  0,
29  1,
30  -123,  //negative integer
31  0234,  //octal number
32  0x1A,  //hexadecimal number
33  PHP_INT_MAX,      // max positive integer number
34  PHP_INT_MAX * 3,  // integer overflow
35  -PHP_INT_MAX - 1, // min negative integer
36
37);
38
39
40// loop through each element of values for 'chunklen'
41for($count = 0; $count < count($values); $count++) {
42  echo "-- Iteration ".($count+1). " --\n";
43  try {
44    var_dump( chunk_split($heredoc_str, $values[$count], $ending) );
45  } catch (TypeError $e) {
46    echo $e->getMessage(), "\n";
47  } catch (\ValueError $e) {
48      echo $e->getMessage() . "\n";
49  }
50}
51
52?>
53--EXPECT--
54*** Testing chunk_split() : different 'chunklen' with heredoc 'str' ***
55-- Iteration 1 --
56chunk_split(): Argument #2 ($length) must be greater than 0
57-- Iteration 2 --
58string(504) "T:::h:::i:::s:::':::s::: :::h:::e:::r:::e:::d:::o:::c::: :::s:::t:::r:::i:::n:::g::: :::w:::i:::t:::h::: :::	::: :::a:::n:::d::: :::
59::: :::w:::h:::i:::t:::e::: :::s:::p:::a:::c:::e::: :::c:::h:::a:::r:::.:::
60:::I:::t::: :::h:::a:::s::: :::_:::s:::p:::e:::c:::i:::@:::l::: :::c:::h:::@:::r:::$::: :::2:::2:::2:::2::: :::!:::!:::!:::N:::o:::w::: :::\:::k::: :::a:::s::: :::e:::s:::c:::a:::p:::e::: :::c:::h:::a:::r::: :::t:::o::: :::t:::e:::s:::t:::
61:::c:::h:::u:::n:::k:::_:::s:::p:::l:::i:::t:::(:::):::"
62-- Iteration 3 --
63chunk_split(): Argument #2 ($length) must be greater than 0
64-- Iteration 4 --
65string(129) "This's heredoc string with 	 and
66 white space char.
67It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
68chunk_split():::"
69-- Iteration 5 --
70string(141) "This's heredoc string with::: 	 and
71 white space char.:::
72It has _speci@l ch@r$ 222:::2 !!!Now \k as escape char::: to test
73chunk_split():::"
74-- Iteration 6 --
75string(129) "This's heredoc string with 	 and
76 white space char.
77It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
78chunk_split():::"
79-- Iteration 7 --
80chunk_split(): Argument #2 ($length) must be of type int, float given
81-- Iteration 8 --
82chunk_split(): Argument #2 ($length) must be greater than 0
83