1--TEST--
2ZE2 A derived class can use the inherited constructor/destructor
3--FILE--
4<?php
5
6// This test checks for:
7// - inherited constructors/destructors are not called automatically
8// - base classes know about derived properties in constructor/destructor
9// - base class constructors/destructors know the instantiated class name
10
11class base {
12    public $name;
13
14    function __construct() {
15        echo __CLASS__ . "::" . __FUNCTION__ . "\n";
16        $this->name = 'base';
17        print_r($this);
18    }
19
20    function __destruct() {
21        echo __CLASS__ . "::" . __FUNCTION__ . "\n";
22        print_r($this);
23    }
24}
25
26class derived extends base {
27    public $other;
28
29    function __construct() {
30        $this->name = 'init';
31        $this->other = 'other';
32        print_r($this);
33        parent::__construct();
34        echo __CLASS__ . "::" . __FUNCTION__ . "\n";
35        $this->name = 'derived';
36        print_r($this);
37    }
38
39    function __destruct() {
40        parent::__destruct();
41        echo __CLASS__ . "::" . __FUNCTION__ . "\n";
42        print_r($this);
43    }
44}
45
46echo "Testing class base\n";
47$t = new base();
48unset($t);
49echo "Testing class derived\n";
50$t = new derived();
51unset($t);
52
53echo "Done\n";
54?>
55--EXPECT--
56Testing class base
57base::__construct
58base Object
59(
60    [name] => base
61)
62base::__destruct
63base Object
64(
65    [name] => base
66)
67Testing class derived
68derived Object
69(
70    [other] => other
71    [name] => init
72)
73base::__construct
74derived Object
75(
76    [other] => other
77    [name] => base
78)
79derived::__construct
80derived Object
81(
82    [other] => other
83    [name] => derived
84)
85base::__destruct
86derived Object
87(
88    [other] => other
89    [name] => derived
90)
91derived::__destruct
92derived Object
93(
94    [other] => other
95    [name] => derived
96)
97Done
98