xref: /PHP-8.1/tests/classes/clone_003.phpt (revision 72c3eded)
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    [p2] => base:2
41    [p3] => test:3
42    [p4] => A
43    [p5] => test:5
44    [p6:base:private] => base:6
45)
46Clown
47test Object
48(
49    [p1] => test:1
50    [p2] => base:2
51    [p3] => test:3
52    [p4] => A
53    [p5] => clone:5
54    [p6:base:private] => base:6
55)
56Done
57