File: ghbug248.phpt

package info (click to toggle)
php-apcu 5.1.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 840 kB
  • sloc: ansic: 4,414; php: 907; xml: 766; makefile: 2
file content (172 lines) | stat: -rw-r--r-- 2,985 bytes parent folder | download | duplicates (4)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--TEST--
GH Bug #248: apcu_fetch may return values causing zend_mm_corruption or segfaults when custom serializer is used
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
apc.enabled=1
apc.enable_cli=1
apc.serializer=default
--FILE--
<?php

function build_array() {
    return [
        'params' => 2,
        'construct' => ['a'],
        'x1' => 'y',
        'x2' => 'y',
        'x3' => 'y',
        'x4' => 'y',
        'x5' => 'y',
        'x6' => 0,
    ];
}

class MyClass {
    private $_params;

    public function __construct($params) {
        var_dump($params);
        $this->_params = $params;
        var_dump($params);
        $this->_params['ids'] = [4];
        $this->_params['loadValue'] = 'x';
        unset($this->_params['params']);
    }
}

function setup() {
    apcu_delete('mytestkey');
    apcu_store('mytestkey', build_array());
}

function test_apcu_fetch() {
    // Or store second?
    $value = apcu_fetch('mytestkey');
    echo "Fetching the value initially stored into apcu:\n";
    var_dump($value);
    echo "Done dumping initial fetch\n\n";

    new MyClass($value);
    echo "\$value was passed by value, not reference. After instantiating class, the array \$value gets modified\n";
    var_dump($value);

    echo "\nAnd calling apcu_fetch again, the original data is preserved (8 keys, params=2)\n";
    var_dump(apcu_fetch('mytestkey'));
}

setup();
test_apcu_fetch();
?>
--EXPECT--
Fetching the value initially stored into apcu:
array(8) {
  ["params"]=>
  int(2)
  ["construct"]=>
  array(1) {
    [0]=>
    string(1) "a"
  }
  ["x1"]=>
  string(1) "y"
  ["x2"]=>
  string(1) "y"
  ["x3"]=>
  string(1) "y"
  ["x4"]=>
  string(1) "y"
  ["x5"]=>
  string(1) "y"
  ["x6"]=>
  int(0)
}
Done dumping initial fetch

array(8) {
  ["params"]=>
  int(2)
  ["construct"]=>
  array(1) {
    [0]=>
    string(1) "a"
  }
  ["x1"]=>
  string(1) "y"
  ["x2"]=>
  string(1) "y"
  ["x3"]=>
  string(1) "y"
  ["x4"]=>
  string(1) "y"
  ["x5"]=>
  string(1) "y"
  ["x6"]=>
  int(0)
}
array(8) {
  ["params"]=>
  int(2)
  ["construct"]=>
  array(1) {
    [0]=>
    string(1) "a"
  }
  ["x1"]=>
  string(1) "y"
  ["x2"]=>
  string(1) "y"
  ["x3"]=>
  string(1) "y"
  ["x4"]=>
  string(1) "y"
  ["x5"]=>
  string(1) "y"
  ["x6"]=>
  int(0)
}
$value was passed by value, not reference. After instantiating class, the array $value gets modified
array(8) {
  ["params"]=>
  int(2)
  ["construct"]=>
  array(1) {
    [0]=>
    string(1) "a"
  }
  ["x1"]=>
  string(1) "y"
  ["x2"]=>
  string(1) "y"
  ["x3"]=>
  string(1) "y"
  ["x4"]=>
  string(1) "y"
  ["x5"]=>
  string(1) "y"
  ["x6"]=>
  int(0)
}

And calling apcu_fetch again, the original data is preserved (8 keys, params=2)
array(8) {
  ["params"]=>
  int(2)
  ["construct"]=>
  array(1) {
    [0]=>
    string(1) "a"
  }
  ["x1"]=>
  string(1) "y"
  ["x2"]=>
  string(1) "y"
  ["x3"]=>
  string(1) "y"
  ["x4"]=>
  string(1) "y"
  ["x5"]=>
  string(1) "y"
  ["x6"]=>
  int(0)
}