count_001.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. JIT COUNT: 001
  3. --INI--
  4. opcache.enable=1
  5. opcache.enable_cli=1
  6. opcache.file_update_protection=0
  7. opcache.jit_buffer_size=1M
  8. ;opcache.jit_debug=1
  9. --EXTENSIONS--
  10. opcache
  11. --FILE--
  12. <?php
  13. class ThrowsInDestructor {
  14. public function __destruct() {
  15. throw new RuntimeException("In destructor");
  16. }
  17. }
  18. class C {
  19. public static function create_array(int $i): array {
  20. return array_fill(0, $i, new stdClass());
  21. }
  22. public static function foo() {
  23. $x = [self::create_array(5)];
  24. echo count(self::create_array(0)), "\n";
  25. echo count(self::create_array(1)), "\n";
  26. echo count($x[0]), "\n";
  27. $a = [];
  28. for ($i = 0; $i < 4; $i++) {
  29. $a[] = $i;
  30. echo count($a) . "\n";
  31. }
  32. }
  33. public static function count_ref(array &$ref): int {
  34. return count($ref);
  35. }
  36. public static function count_throws(): int {
  37. $result = count([new ThrowsInDestructor()]);
  38. echo "Unreachable\n";
  39. return $result;
  40. }
  41. }
  42. C::foo();
  43. $x = ['x', 'y', 'z', 'a', new stdClass()];
  44. echo C::count_ref($x), "\n";
  45. for ($i = 0; $i < 5; $i++) {
  46. try {
  47. echo C::count_throws(), "\n";
  48. } catch (RuntimeException $e) {
  49. printf("Caught %s\n", $e->getMessage());
  50. }
  51. }
  52. --EXPECT--
  53. 0
  54. 1
  55. 5
  56. 1
  57. 2
  58. 3
  59. 4
  60. 5
  61. Caught In destructor
  62. Caught In destructor
  63. Caught In destructor
  64. Caught In destructor
  65. Caught In destructor