bug77135.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. Test extract() with $this
  3. --FILE--
  4. <?php
  5. class Extract
  6. {
  7. public function run(): void
  8. {
  9. $options = [
  10. 'EXTR_OVERWRITE' => EXTR_OVERWRITE,
  11. 'EXTR_SKIP' => EXTR_SKIP,
  12. 'EXTR_PREFIX_SAME' => EXTR_PREFIX_SAME,
  13. 'EXTR_PREFIX_ALL' => EXTR_PREFIX_ALL,
  14. 'EXTR_PREFIX_INVALID' => EXTR_PREFIX_INVALID,
  15. 'EXTR_IF_EXISTS' => EXTR_IF_EXISTS,
  16. 'EXTR_PREFIX_IF_EXISTS' => EXTR_PREFIX_IF_EXISTS,
  17. ];
  18. foreach ($options as $name => $flags) {
  19. echo "{$name}\n";
  20. $this->handle($name, $flags);
  21. $this->handle("{$name}_REFS", $flags | EXTR_REFS);
  22. echo "\n";
  23. }
  24. }
  25. private function handle(string $name, int $flags): void
  26. {
  27. $array = ["this" => "value"];
  28. try {
  29. $result = extract($array, $flags, "x");
  30. echo " extract() = {$result}\n";
  31. echo " \$this = " . get_class($this) . "\n";
  32. echo " \$v_this = " . (isset($x_this) ? $x_this : "NULL") . "\n";
  33. } catch (\Throwable $e) {
  34. echo " Exception: " . $e->getMessage() . "\n";
  35. }
  36. }
  37. }
  38. (new Extract)->run();
  39. ?>
  40. --EXPECT--
  41. EXTR_OVERWRITE
  42. Exception: Cannot re-assign $this
  43. Exception: Cannot re-assign $this
  44. EXTR_SKIP
  45. extract() = 0
  46. $this = Extract
  47. $v_this = NULL
  48. extract() = 0
  49. $this = Extract
  50. $v_this = NULL
  51. EXTR_PREFIX_SAME
  52. extract() = 1
  53. $this = Extract
  54. $v_this = value
  55. extract() = 1
  56. $this = Extract
  57. $v_this = value
  58. EXTR_PREFIX_ALL
  59. extract() = 1
  60. $this = Extract
  61. $v_this = value
  62. extract() = 1
  63. $this = Extract
  64. $v_this = value
  65. EXTR_PREFIX_INVALID
  66. extract() = 1
  67. $this = Extract
  68. $v_this = value
  69. extract() = 1
  70. $this = Extract
  71. $v_this = value
  72. EXTR_IF_EXISTS
  73. extract() = 0
  74. $this = Extract
  75. $v_this = NULL
  76. extract() = 0
  77. $this = Extract
  78. $v_this = NULL
  79. EXTR_PREFIX_IF_EXISTS
  80. extract() = 0
  81. $this = Extract
  82. $v_this = NULL
  83. extract() = 0
  84. $this = Extract
  85. $v_this = NULL