xref: /php-src/Zend/tests/bug38220.phpt (revision f8d79582)
1--TEST--
2Bug #38220 (Crash on some object operations)
3--FILE--
4<?php
5class drv {
6    public $obj;
7
8    function func1() {
9        echo "func1(): {$this->obj->i}\n";
10    }
11
12    function close() {
13        echo "close(): {$this->obj->i}\n";
14    }
15}
16
17class A {
18    public $i;
19
20    function __construct($i) {
21        $this->i = $i;
22
23    }
24
25    function __call($method, $args) {
26        $drv = myserv::drv();
27
28        $drv->obj = $this;
29
30        echo "before call $method\n";
31        print_r($this);
32        call_user_func_array(array($drv, $method), $args);
33        echo "after call $method\n";
34
35        // Uncomment this line to work without crash
36//		$drv->obj = null;
37    }
38
39    function __destruct() {
40        echo "A::__destruct()\n";
41        $this->close();
42    }
43}
44
45class myserv {
46    private static $drv = null;
47
48    static function drv() {
49        if (is_null(self::$drv))
50            self::$drv = new drv;
51        return self::$drv;
52    }
53}
54
55$obj1 = new A(1);
56$obj1->func1();
57
58$obj2 = new A(2);
59unset($obj1);
60$obj2->func1();
61?>
62--EXPECT--
63before call func1
64A Object
65(
66    [i] => 1
67)
68func1(): 1
69after call func1
70A::__destruct()
71before call close
72A Object
73(
74    [i] => 1
75)
76close(): 1
77after call close
78before call func1
79A Object
80(
81    [i] => 2
82)
83func1(): 1
84after call func1
85A::__destruct()
86before call close
87A Object
88(
89    [i] => 2
90)
91close(): 2
92after call close
93