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