1--TEST--
2Lazy objects: RFC example 009
3--FILE--
4<?php
5
6class Connection {
7    public $prop;
8    public function __construct() {
9        $this->connect();
10    }
11    public function __destruct() {
12        var_dump(__METHOD__);
13        $this->close();
14    }
15    public function connect() {
16    }
17    public function close() {
18    }
19}
20
21$connection = new Connection();
22
23$reflector = new ReflectionClass(Connection::class);
24
25print "Reset non-lazy\n";
26// Calls destructor
27$reflector->resetAsLazyGhost($connection, function () {
28    var_dump("initialization");
29});
30
31print "Release non-initialized\n";
32$connection = null; // Does not call destructor (object is not initialized)
33
34?>
35==DONE==
36--EXPECT--
37Reset non-lazy
38string(22) "Connection::__destruct"
39Release non-initialized
40==DONE==
41