1--TEST-- 2Test clone of objects whose class derived from DateTime class 3--FILE-- 4<?php 5//Set the default time zone 6date_default_timezone_set("Europe/London"); 7 8class DateTimeExt1 extends DateTime { 9 public $property1 = 99; 10 public $property2 = "Hello"; 11 12} 13 14class DateTimeExt2 extends DateTimeExt1 { 15 public $property3 = true; 16 public $property4 = 10.5; 17} 18 19echo "*** Testing clone on objects whose class derived from DateTime class ***\n"; 20 21$d1 = new DateTimeExt1("2009-02-03 12:34:41 GMT"); 22var_dump($d1); 23$d1_clone = clone $d1; 24var_dump($d1_clone); 25 26$d2 = new DateTimeExt2("2009-02-03 12:34:41 GMT"); 27var_dump($d2); 28$d2_clone = clone $d2; 29var_dump($d2_clone); 30?> 31--EXPECTF-- 32*** Testing clone on objects whose class derived from DateTime class *** 33object(DateTimeExt1)#%d (5) { 34 ["property1"]=> 35 int(99) 36 ["property2"]=> 37 string(5) "Hello" 38 ["date"]=> 39 string(26) "2009-02-03 12:34:41.000000" 40 ["timezone_type"]=> 41 int(2) 42 ["timezone"]=> 43 string(3) "GMT" 44} 45object(DateTimeExt1)#%d (5) { 46 ["property1"]=> 47 int(99) 48 ["property2"]=> 49 string(5) "Hello" 50 ["date"]=> 51 string(26) "2009-02-03 12:34:41.000000" 52 ["timezone_type"]=> 53 int(2) 54 ["timezone"]=> 55 string(3) "GMT" 56} 57object(DateTimeExt2)#%d (7) { 58 ["property1"]=> 59 int(99) 60 ["property2"]=> 61 string(5) "Hello" 62 ["property3"]=> 63 bool(true) 64 ["property4"]=> 65 float(10.5) 66 ["date"]=> 67 string(26) "2009-02-03 12:34:41.000000" 68 ["timezone_type"]=> 69 int(2) 70 ["timezone"]=> 71 string(3) "GMT" 72} 73object(DateTimeExt2)#%d (7) { 74 ["property1"]=> 75 int(99) 76 ["property2"]=> 77 string(5) "Hello" 78 ["property3"]=> 79 bool(true) 80 ["property4"]=> 81 float(10.5) 82 ["date"]=> 83 string(26) "2009-02-03 12:34:41.000000" 84 ["timezone_type"]=> 85 int(2) 86 ["timezone"]=> 87 string(3) "GMT" 88} 89