jimdev Posted August 9, 2009 Share Posted August 9, 2009 I change one date with date_modify and others that are set to the same value change. It seems like instead of assigning values, = is pointing all these variables at each other? Very odd! $date = date_create('2009-8'); $next_date = 0; $b = date_create('1970-1-1'); echo 'TEST $date: '.date_format($date, 'Ym')."\n<br/>"; $next_date = $date; echo 'TEST $date: '.date_format($date, 'Ym')."\n<br/>"; $mod = '+'.date_format($date, 't').' day'."\n<br/>"; echo 'TEST $date: '.date_format($date, 'Ym')."\n<br/>"; echo $mod; echo 'TEST $date: '.date_format($date, 'Ym')."\n<br/>"; $a = $next_date; echo 'TEST $a: '.date_format($a, 'Ym')."\n<br/>"; echo 'TEST $b: '.date_format($b, 'Ym')."\n<br/>"; $date = $date; $next_date->modify($mod); echo 'TEST $date: '.date_format($date, 'Ym')."\n<br/>"; echo 'TEST $next_date: '.date_format($next_date, 'Ym')."\n<br/>"; echo 'TEST $a: '.date_format($a, 'Ym')."\n<br/>"; echo 'TEST $b: '.date_format($b, 'Ym')."\n<br/>"; Expected results TEST $date: 200908 TEST $date: 200908 TEST $date: 200908 +31 day TEST $date: 200908 TEST $a: 200908 TEST $b: 197001 TEST $date: 200908 <----- TEST $next_date: 200909 TEST $a: 200908 <------ TEST $b: 197001 Actual Results TEST $date: 200908 TEST $date: 200908 TEST $date: 200908 +31 day TEST $date: 200908 TEST $a: 200908 TEST $b: 197001 TEST $date: 200909 <---- changes? why? TEST $next_date: 200909 TEST $a: 200909 <----- changes? why? TEST $b: 197001 I have PHP 5.2.8 installed on Apache 2.0 Any idea what's wrong here? I feel like an idiot going around in circles. Link to comment https://forums.phpfreaks.com/topic/169429-strange-date_modify-behaviour-pls-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.