already_occupied.phpt 753 B

123456789101112131415161718192021222324252627282930313233
  1. --TEST--
  2. Appending to an array via unpack may fail
  3. --SKIPIF--
  4. <?php if (PHP_INT_SIZE != 8) die("skip 64bit only"); ?>
  5. --FILE--
  6. <?php
  7. $arr = [1, 2, 3];
  8. try {
  9. var_dump([PHP_INT_MAX-1 => 0, ...$arr]);
  10. } catch (Error $e) {
  11. echo $e->getMessage(), "\n";
  12. }
  13. try {
  14. var_dump([PHP_INT_MAX-1 => 0, ...[1, 2, 3]]);
  15. } catch (Error $e) {
  16. echo $e->getMessage(), "\n";
  17. }
  18. const ARR = [1, 2, 3];
  19. function test($x = [PHP_INT_MAX-1 => 0, ...ARR]) {}
  20. try {
  21. test();
  22. } catch (Error $e) {
  23. echo $e->getMessage(), "\n";
  24. }
  25. ?>
  26. --EXPECT--
  27. Cannot add element to the array as the next element is already occupied
  28. Cannot add element to the array as the next element is already occupied
  29. Cannot add element to the array as the next element is already occupied