xref: /PHP-7.4/tests/classes/clone_003.phpt (revision a8d901a8)
1--TEST--
2ZE2 object cloning, 3
3--FILE--
4<?php
5class base {
6	protected $p1 = 'base:1';
7	public $p2 = 'base:2';
8	public $p3 = 'base:3';
9	public $p4 = 'base:4';
10	public $p5 = 'base:5';
11	private $p6 = 'base:6';
12	public function __clone() {
13	}
14};
15
16class test extends base {
17	public $p1 = 'test:1';
18	public $p3 = 'test:3';
19	public $p4 = 'test:4';
20	public $p5 = 'test:5';
21	public function __clone() {
22		$this->p5 = 'clone:5';
23	}
24}
25
26$obj = new test;
27$obj->p4 = 'A';
28$copy = clone $obj;
29echo "Object\n";
30print_r($obj);
31echo "Clown\n";
32print_r($copy);
33echo "Done\n";
34?>
35--EXPECT--
36Object
37test Object
38(
39    [p1] => test:1
40    [p3] => test:3
41    [p4] => A
42    [p5] => test:5
43    [p2] => base:2
44    [p6:base:private] => base:6
45)
46Clown
47test Object
48(
49    [p1] => test:1
50    [p3] => test:3
51    [p4] => A
52    [p5] => clone:5
53    [p2] => base:2
54    [p6:base:private] => base:6
55)
56Done
57