1--TEST--
2Lazy Objects: GH-15999 002: Assigned value is changed during lazy object initialization
3--FILE--
4<?php
5
6class C {
7    public $s;
8    public function __destruct() {
9        var_dump(__METHOD__);
10    }
11}
12
13print "# Ghost:\n";
14
15$r = new ReflectionClass(C::class);
16
17$o = $r->newLazyGhost(function ($obj) {
18    global $p;
19    $p = null;
20});
21
22$p = new stdClass;
23var_dump($o->s = $p);
24var_dump($o->s);
25
26print "# Proxy:\n";
27
28$r = new ReflectionClass(C::class);
29
30$o = $r->newLazyProxy(function ($obj) {
31    global $p;
32    $p = null;
33    return new C();
34});
35
36$p = new stdClass;
37var_dump($o->s = $p);
38var_dump($o->s);
39
40?>
41==DONE==
42--EXPECTF--
43# Ghost:
44object(stdClass)#%d (0) {
45}
46object(stdClass)#%d (0) {
47}
48# Proxy:
49string(13) "C::__destruct"
50object(stdClass)#%d (0) {
51}
52object(stdClass)#%d (0) {
53}
54==DONE==
55string(13) "C::__destruct"
56