1

I'm in the process of migrating an old piece of code to PHP 8.1 from (hold on to your hat...) PHP 4.2!

However I did make significate progress. I ran in to the following statement

if ($arr[$key]) {
    array_splice($arr[$key]);
}

var_dump shows

$key = 'a';
$arr = ['a' => 1];

Obviously this breaks on 8.1 for 2 reasons

  1. int is passed as an array.
  2. offset is ignored.

I'm having trouble under standing what would have been the behavior of this code under PHP 4.2
Looking at the 4.x documentation of array_splice does not explain.

Thank's

phper
  • 307
  • 2
  • 12
  • You can run PHP4 here, https://3v4l.org/RF0Ng#v4.3.0. Without values hard to tell though – user3783243 Nov 29 '22 at 18:57
  • OMG thank you, this will help me tremendous. I added values https://3v4l.org/YAVEr#v4.3.0 it errors out `Warning: Wrong parameter count for array_splice() in /in/YAVEr on line 6` So I guess if `display_errors` was 0 then it simply would ignore this line? – phper Nov 29 '22 at 19:00
  • Seems like it. This is a version behind yours. Looks like https://onlinephp.io/ could be used for 4.2 testing. – user3783243 Nov 29 '22 at 19:22
  • Yes, whatever this line was _intended_ to do, it _actually_ does nothing other than emit a warning. – Sammitch Nov 29 '22 at 21:20

1 Answers1

1

It emits a warning so it would simply skip this line and continue execution

MIgrated code looks like this

if ($arr[$key] && is_array($arr[$key])) {
    array_splice($arr[$key], 0);
}
phper
  • 307
  • 2
  • 12