Advertisement
Guest User

PHP opcache bug, complex expression in if

a guest
Oct 4th, 2020
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. #region setup
  3. //   Tests 1 and 2: exit after first item in php8.0.0rc1
  4. //   php.ini
  5. //   zend_extension=opcache
  6. //   opcache.enable=1
  7. //   opcache.enable_cli=1
  8. //   opcache.memory_consumption=128
  9. $factory = function (string $msg): Closure {
  10.     return function () use ($msg): void {
  11.         fwrite(STDOUT, $msg);
  12.     };
  13. };
  14.  
  15. $initial_callbacks = [
  16.     $factory('First item!'),
  17.     $factory('Second item!'),
  18.     $factory('Third item!'),
  19.     $factory('Fourth item!'),
  20. ];
  21.  
  22. $nl = function (): void {
  23.     fwrite(STDOUT, PHP_EOL);
  24. };
  25. #endregion setup
  26.  
  27. fwrite(STDOUT, PHP_EOL);
  28.  
  29. fwrite(STDOUT, 'START: Test all work done in argument.' . PHP_EOL);
  30. $array = $initial_callbacks;
  31.  
  32. while ((null !== $callback = array_shift($array)) && ($callback() || $nl() || true))
  33.     /**/;
  34.  
  35. fwrite(STDOUT, 'END:   Test all work done in argument.' . PHP_EOL . PHP_EOL . PHP_EOL);
  36.  
  37.  
  38. fwrite(STDOUT, 'START: Test all work done in body inside if.' . PHP_EOL);
  39. $array = $initial_callbacks;
  40.  
  41. while (true) {
  42.     if (!((null !== $callback = array_shift($array)) && ($callback() || $nl() || true))) {
  43.         break;
  44.     }
  45. }
  46. fwrite(STDOUT, 'END:   Test all work done in body inside if.' . PHP_EOL . PHP_EOL . PHP_EOL);
  47.  
  48.  
  49. fwrite(STDOUT, 'START: Test all work done in body print result.' . PHP_EOL);
  50. $array = $initial_callbacks;
  51.  
  52. while (true) {
  53.     $result = (null !== $callback = array_shift($array)) && ($callback() || $nl() || true);
  54.     if (!$result) {
  55.         break;
  56.     }
  57.  
  58.     fwrite(STDOUT, $result . PHP_EOL);
  59. }
  60. fwrite(STDOUT, 'END:   Test all work done in body print result.' . PHP_EOL);
  61.  
  62. die(PHP_EOL);
  63.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement