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_slice() - Third parameter (NULL vs 0) --FILE-- <?php var_dump(array_s..

Decoded Output download

--TEST--
Test array_slice() - Third parameter (NULL vs 0)
--FILE--
<?php

var_dump(array_slice(range(1, 3), 0, NULL, 1));
var_dump(array_slice(range(1, 3), 0, 0, 1));
var_dump(array_slice(range(1, 3), 0, NULL));
var_dump(array_slice(range(1, 3), 0, 0));

var_dump(array_slice(range(1, 3), -1, 0));
var_dump(array_slice(range(1, 3), -1, 0, 1));
var_dump(array_slice(range(1, 3), -1, NULL));
var_dump(array_slice(range(1, 3), -1, NULL, 1));


$a = 'foo';
try {
    var_dump(array_slice(range(1, 3), 0, $a));
} catch (TypeError $e) {
    echo $e->getMessage(), "
";
}
try {
    var_dump(array_slice(range(1, 3), 0, $a));
} catch (TypeError $e) {
    echo $e->getMessage(), "
";
}
var_dump($a);

?>
--EXPECT--
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(0) {
}
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(0) {
}
array(0) {
}
array(0) {
}
array(1) {
  [0]=>
  int(3)
}
array(1) {
  [2]=>
  int(3)
}
array_slice(): Argument #3 ($length) must be of type ?int, string given
array_slice(): Argument #3 ($length) must be of type ?int, string given
string(3) "foo"

Did this file decode correctly?

Original Code

--TEST--
Test array_slice() - Third parameter (NULL vs 0)
--FILE--
<?php

var_dump(array_slice(range(1, 3), 0, NULL, 1));
var_dump(array_slice(range(1, 3), 0, 0, 1));
var_dump(array_slice(range(1, 3), 0, NULL));
var_dump(array_slice(range(1, 3), 0, 0));

var_dump(array_slice(range(1, 3), -1, 0));
var_dump(array_slice(range(1, 3), -1, 0, 1));
var_dump(array_slice(range(1, 3), -1, NULL));
var_dump(array_slice(range(1, 3), -1, NULL, 1));


$a = 'foo';
try {
    var_dump(array_slice(range(1, 3), 0, $a));
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(array_slice(range(1, 3), 0, $a));
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
var_dump($a);

?>
--EXPECT--
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(0) {
}
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(0) {
}
array(0) {
}
array(0) {
}
array(1) {
  [0]=>
  int(3)
}
array(1) {
  [2]=>
  int(3)
}
array_slice(): Argument #3 ($length) must be of type ?int, string given
array_slice(): Argument #3 ($length) must be of type ?int, string given
string(3) "foo"

Function Calls

range 1

Variables

None

Stats

MD5 6cb91255c0a311f5123541633778382f
Eval Count 0
Decode Time 95 ms