xref: /PHP-5.6/tests/classes/clone_004.phpt (revision 610c7fbe)
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  // reenable 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  ["b"]=>
44  array(2) {
45    [0]=>
46    int(3)
47    [1]=>
48    int(4)
49  }
50  ["a"]=>
51  array(2) {
52    [0]=>
53    int(1)
54    [1]=>
55    int(2)
56  }
57}
58Clone
59object(test)#2 (2) {
60  ["b"]=>
61  array(2) {
62    [0]=>
63    int(3)
64    [1]=>
65    int(4)
66  }
67  ["a"]=>
68  array(2) {
69    [0]=>
70    int(1)
71    [1]=>
72    int(2)
73  }
74}
75Modify
76object(test)#2 (2) {
77  ["b"]=>
78  int(6)
79  ["a"]=>
80  int(5)
81}
82Done
83