summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/bug77135.phpt
blob: 0b23d627662680502103490c235aa5672b675a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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