Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test array_unshift() function : usage variations - heredoc strings for 'var' argu..

Decoded Output download

*** Testing array_unshift() : heredoc strings for \$var argument ***
-- Iteration 1 --

Did this file decode correctly?

Original Code

--TEST--
Test array_unshift() function : usage variations - heredoc strings for 'var' argument
--FILE--
<?php
/*
 * Testing the functionality of array_unshift() by passing different
 * heredoc strings for $var argument that is prepended to the array
 * passed through $array argument
*/

echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n";

// heredoc with empty value
$empty_string = <<<EOT
EOT;

// heredoc with blank line
$blank_line = <<<EOT


EOT;

// heredoc with multiline string
$multiline_string = <<<EOT
hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string
EOT;

// heredoc with different whitespaces
$diff_whitespaces = <<<EOT
hello\r world\t
1111\t\t != 2222\v\v
heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
EOT;

// heredoc with numeric values
$numeric_string = <<<EOT
11 < 12. 123 >22
2222 != 1111.\t 0000 = 0000\n
EOT;

// heredoc with quote chars & slash
$quote_char_string = <<<EOT
This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes
EOT;

// array to be passed to $array argument
$array = array('f' => "first", "s" => 'second', 1, 2.222);

// different heredoc strings to be passed to $var argument
$vars = array(
  $empty_string,
  $blank_line,
  $multiline_string,
  $diff_whitespaces,
  $numeric_string,
  $quote_char_string
);

// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($vars as $var) {
  echo "-- Iteration $iterator --\n";
  $temp_array = $array;  // assign $array to another temporary $temp_array

  /* with default argument */
  // returns element count in the resulting array after arguments are pushed to
  // beginning of the given array
  var_dump( array_unshift($temp_array, $var) );

  // dump the resulting array
  var_dump($temp_array);

  /* with all possible arguments */
  // returns element count in the resulting array after arguments are pushed to
  // beginning of the given array
  $temp_array = $array;
  var_dump( array_unshift($temp_array, $var, "hello", 'world') );

  // dump the resulting array
  var_dump($temp_array);
  $iterator++;
}

echo "Done";
?>
--EXPECT--
*** Testing array_unshift() : heredoc strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
  [0]=>
  string(0) ""
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(0) ""
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
  [0]=>
  string(1) "
"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(1) "
"
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
  [0]=>
  string(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
  [0]=>
  string(88) "hello
 world	
1111		 != 2222
heredoc
double quoted string. withdifferentwhitespaces"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(88) "hello
 world	
1111		 != 2222
heredoc
double quoted string. withdifferentwhitespaces"
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
  [0]=>
  string(44) "11 < 12. 123 >22
2222 != 1111.	 0000 = 0000
"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(44) "11 < 12. 123 >22
2222 != 1111.	 0000 = 0000
"
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
-- Iteration 6 --
int(5)
array(5) {
  [0]=>
  string(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [1]=>
  int(1)
  [2]=>
  float(2.222)
}
int(7)
array(7) {
  [0]=>
  string(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
  [1]=>
  string(5) "hello"
  [2]=>
  string(5) "world"
  ["f"]=>
  string(5) "first"
  ["s"]=>
  string(6) "second"
  [3]=>
  int(1)
  [4]=>
  float(2.222)
}
Done

Function Calls

array_unshift 1

Variables

$var
$vars [{'key': 0, 'value': ''}, {'key': 1, 'value': '\n\n'}, {'key': 2, 'value': 'hello world\nThe big brown fox jumped over;\nthe lazy dog\nThis is a double quoted string\n'}, {'key': 3, 'value': 'hello\r world\t\n1111\t\t != 2222\x0b\x0b\nheredoc\ndouble quoted string. with\x0bdifferent\x0cwhite\x0bspaces\n'}, {'key': 4, 'value': '11 < 12. 123 >22\n2222 != 1111.\t 0000 = 0000\n\n'}, {'key': 5, 'value': 'This\'s a string with quotes:\n"strings in double quote";\n\'strings in single quote\';\nthis\\line is single quoted /with\\slashes\n'}]
$array [{'key': 'f', 'value': 'first'}, {'key': 's', 'value': 'second'}, {'key': 2, 'value': 1}, {'key': 3, 'value': 2.222}]
$iterator 1
$blank_line
$temp_array [{'key': 'f', 'value': 'first'}, {'key': 's', 'value': 'second'}, {'key': 2, 'value': 1}, {'key': 3, 'value': 2.222}]
$empty_string
$numeric_string 11 < 12. 123 >22 2222 != 1111. 0000 = 0000
$diff_whitespaces hello world 1111 != 2222 heredoc double quoted string...
$multiline_string hello world The big brown fox jumped over; the lazy dog This..
$quote_char_string This's a string with quotes: "strings in double quote"; 'str..

Stats

MD5 46240cb5602ebd8b3456d7a79ce7a0d3
Eval Count 0
Decode Time 103 ms