xref: /PHP-8.3/tests/classes/clone_004.phpt (revision 72c3eded)
1--TEST--
2ZE2 object cloning, 4
3--FILE--
4<?php
5abstract class base {
6  public $a = 'base';
7
8  // disallow cloning
9  private function __clone() {}
10}
11
12class test extends base {
13  public $b = 'test';
14
15  // re-enable cloning
16  public function __clone() {}
17
18  public function show() {
19    var_dump($this);
20  }
21}
22
23echo "Original\n";
24$o1 = new test;
25$o1->a = array(1,2);
26$o1->b = array(3,4);
27$o1->show();
28
29echo "Clone\n";
30$o2 = clone $o1;
31$o2->show();
32
33echo "Modify\n";
34$o2->a = 5;
35$o2->b = 6;
36$o2->show();
37
38echo "Done\n";
39?>
40--EXPECT--
41Original
42object(test)#1 (2) {
43  ["a"]=>
44  array(2) {
45    [0]=>
46    int(1)
47    [1]=>
48    int(2)
49  }
50  ["b"]=>
51  array(2) {
52    [0]=>
53    int(3)
54    [1]=>
55    int(4)
56  }
57}
58Clone
59object(test)#2 (2) {
60  ["a"]=>
61  array(2) {
62    [0]=>
63    int(1)
64    [1]=>
65    int(2)
66  }
67  ["b"]=>
68  array(2) {
69    [0]=>
70    int(3)
71    [1]=>
72    int(4)
73  }
74}
75Modify
76object(test)#2 (2) {
77  ["a"]=>
78  int(5)
79  ["b"]=>
80  int(6)
81}
82Done
83