pastebin

Paste Search Dynamic
Recent pastes
output()
  1. <?php
  2. function output($t1, $t1_chg, $title) {
  3.     $format = 'Y-m-d D H:i:s.v e';
  4.     echo '----- ' . $title . ' -----' . PHP_EOL;
  5.     echo 'DateTime org         : ' . $t1->format($format) . PHP_EOL;
  6.     if( $t1_chg ) echo 'DateTime chg         : ' . $t1_chg->format($format) . PHP_EOL;
  7.     echo PHP_EOL;
  8. }
  9.  
  10. $time = '2010-01-01 01:01:01.111';
  11. // Immutableに変更
  12. //$t1 = new DateTime($time);
  13. $t1 = new DateTimeImmutable($time);
  14.  
  15. function change($t1) {
  16.     $year = 2011;
  17.     $month = 2;
  18.     $day = 2;
  19.     $t1_chg = $t1->setDate($year, $month, $day);
  20.     output($t1, $t1_chg, 'function change');   
  21. }
  22. change($t1);
  23.  
  24. class Sample {
  25.         private $obj;
  26.        
  27.         function __construct($obj){
  28.                 $this->obj = $obj;
  29.         }
  30.        
  31.         public function get_obj() {
  32.                 $tmp = $this->obj;
  33.                 $year = 2012;
  34.         $month = 3;
  35.         $day = 3;
  36.         $tmp_chg = $tmp->setDate($year, $month, $day);
  37.         output($this->obj, $tmp_chg, 'Sample Object get_obj')
  38.                 return $this->obj;
  39.         }
  40. }
  41. $sample = new Sample($t1);
  42. $sample->get_obj();
  43.  
  44. output($t1, null, 'use continue');     
  45.  
  46. ?>
Parsed in 0.023 seconds