diff options
author | Dmitry Stogov <dmitry@zend.com> | 2019-06-07 11:36:39 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2019-06-07 11:36:39 +0300 |
commit | 83cdb89f8a6cbc656f2f95aeb6ce1c97691e197f (patch) | |
tree | 027957cf578ec8d7640242728fd33e4b8c29f534 /ext/standard/tests/array/bug77135.phpt | |
parent | 7d1aa7534d756477d45f8fa63b5467589ccca031 (diff) | |
download | php-git-83cdb89f8a6cbc656f2f95aeb6ce1c97691e197f.tar.gz |
Fixed bug #77135 (Extract with EXTR_SKIP should skip $this)
Diffstat (limited to 'ext/standard/tests/array/bug77135.phpt')
-rw-r--r-- | ext/standard/tests/array/bug77135.phpt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/ext/standard/tests/array/bug77135.phpt b/ext/standard/tests/array/bug77135.phpt new file mode 100644 index 0000000000..0b23d62766 --- /dev/null +++ b/ext/standard/tests/array/bug77135.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test extract() with $this +--FILE-- +<?php + +class Extract +{ + public function run(): void + { + $options = [ + 'EXTR_OVERWRITE' => EXTR_OVERWRITE, + 'EXTR_SKIP' => EXTR_SKIP, + 'EXTR_PREFIX_SAME' => EXTR_PREFIX_SAME, + 'EXTR_PREFIX_ALL' => EXTR_PREFIX_ALL, + 'EXTR_PREFIX_INVALID' => EXTR_PREFIX_INVALID, + 'EXTR_IF_EXISTS' => EXTR_IF_EXISTS, + 'EXTR_PREFIX_IF_EXISTS' => EXTR_PREFIX_IF_EXISTS, + ]; + + foreach ($options as $name => $flags) { + echo "{$name}\n"; + + $this->handle($name, $flags); + $this->handle("{$name}_REFS", $flags | EXTR_REFS); + echo "\n"; + } + } + + private function handle(string $name, int $flags): void + { + $array = ["this" => "value"]; + + try { + $result = extract($array, $flags, "x"); + echo " extract() = {$result}\n"; + + echo " \$this = " . get_class($this) . "\n"; + echo " \$v_this = " . (isset($x_this) ? $x_this : "NULL") . "\n"; + } catch (\Throwable $e) { + echo " Exception: " . $e->getMessage() . "\n"; + } + } +} + +(new Extract)->run(); + +?> +--EXPECT-- +EXTR_OVERWRITE + Exception: Cannot re-assign $this + Exception: Cannot re-assign $this + +EXTR_SKIP + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL + +EXTR_PREFIX_SAME + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_PREFIX_ALL + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_PREFIX_INVALID + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_IF_EXISTS + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL + +EXTR_PREFIX_IF_EXISTS + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL |