bmb Posted February 29, 2008 Share Posted February 29, 2008 Very simple script produces different output when executed in a terminal and a browser. I've been banging my head against the wall trying to figure this out... Maybe someone smarter than I can.. This script is very simple and does the following: Prints the Date and the Week Before Date Makes the Week Before Current and Gets the Week Before That Here's the Code: <?php class metricInfo { var $weekEnd; } // setup today $epoc = gettimeofday(); $today = date('Y-m-d', $epoc['sec']); // print html header print "<html>\n"; print "<head>\n"; print"<title>Macallan Bug Metrics v1.0</title>\n"; print "</head>\n"; print "<body>\n"; // just confirm the time... print "Today is: $today<br>\n"; // get two new instances $thisWeek = new metricInfo; $prevWeek = new metricInfo; // setup today $thisWeek->weekEnd = $today; for ($i= 0; $i < 4; $i++){ // tell me what last week was $date = $epoc['sec'] - (86400 * (7 * ($i+1))); $prevWeek->weekEnd = date('Y-m-d', $date); print("debug: i = $i thisWeek: $thisWeek->weekEnd prevWeek: $prevWeek->weekEnd<br>\n"); // last week is now the current week... $thisWeek = $prevWeek; print("debug: i = $i thisWeek: $thisWeek->weekEnd prevWeek: $prevWeek->weekEnd<br><br>\n"); } print "</body>\n"; print "</html>\n"; ?> The output from the Terminal is: bmb-macbook:~/Projects/Metrics-Stage brianboerner$ php confuse.php Today is: 2008-02-29<br> debug: i = 0 thisWeek: 2008-02-29 prevWeek: 2008-02-22 debug: i = 0 thisWeek: 2008-02-22 prevWeek: 2008-02-22 debug: i = 1 thisWeek: 2008-02-22 prevWeek: 2008-02-15 debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15 debug: i = 2 thisWeek: 2008-02-15 prevWeek: 2008-02-08 debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08 debug: i = 3 thisWeek: 2008-02-08 prevWeek: 2008-02-01 debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01 The output from a web browser is: Today is: 2008-02-29 debug: i = 0 thisWeek: 2008-02-29 prevWeek: 2008-02-22 debug: i = 0 thisWeek: 2008-02-22 prevWeek: 2008-02-22 debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15 debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15 debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08 debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08 debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01 debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01 Notice how after the first time through the loop the browser skips a week and the dates never differ; compared to the terminal that works as it's suppose to... However... here's an interesting tid bit. If I change this line: $thisWeek = $prevWeek; to $thisWeek = &$prevWeek; THEN, the terminal matches the web browser, as I would expect. So, I'm trying to figure out how to get the first example to work. It's like the browser is interpreting the copy as an address assignment. Any Thoughts? bmb Quote Link to comment https://forums.phpfreaks.com/topic/93756-why-is-the-output-different-for-this-script/ Share on other sites More sharing options...
ignace Posted February 29, 2008 Share Posted February 29, 2008 obviously a php.ini issue alter the php.ini path for your terminal, and you will most likely get the same output Quote Link to comment https://forums.phpfreaks.com/topic/93756-why-is-the-output-different-for-this-script/#findComment-480418 Share on other sites More sharing options...
bmb Posted February 29, 2008 Author Share Posted February 29, 2008 But I want the browser to be the same as the terminal... Sorry. I'm pretty new. I've only been writing php code for about a week now... It still doesn't explain what *causes* them to be different. Are you saying I'm calling a different version from one place than the other? Quote Link to comment https://forums.phpfreaks.com/topic/93756-why-is-the-output-different-for-this-script/#findComment-480431 Share on other sites More sharing options...
bmb Posted March 1, 2008 Author Share Posted March 1, 2008 OK.. You were right.. but can someone explain to me why php4 and php5 treat the code differently.. and how do I get php5 to treat it like php4 does (which is the desired output). localhost:~/Projects/Metrics-Stage brianboerner$ which php /usr/bin/php localhost:~/Projects/Metrics-Stage brianboerner$ php confuse.php Today is: 2008-02-29<br> debug: i = 0 thisWeek: 2008-02-29 prevWeek: 2008-02-22<br> debug: i = 0 thisWeek: 2008-02-22 prevWeek: 2008-02-22<br><br> debug: i = 1 thisWeek: 2008-02-22 prevWeek: 2008-02-15<br> debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15<br><br> debug: i = 2 thisWeek: 2008-02-15 prevWeek: 2008-02-08<br> debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08<br><br> debug: i = 3 thisWeek: 2008-02-08 prevWeek: 2008-02-01<br> debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01<br><br> localhost:~/Projects/Metrics-Stage brianboerner$ /usr/local/php5/bin/php confuse.php Today is: 2008-02-29<br> debug: i = 0 thisWeek: 2008-02-29 prevWeek: 2008-02-22<br> debug: i = 0 thisWeek: 2008-02-22 prevWeek: 2008-02-22<br><br> debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15<br> debug: i = 1 thisWeek: 2008-02-15 prevWeek: 2008-02-15<br><br> debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08<br> debug: i = 2 thisWeek: 2008-02-08 prevWeek: 2008-02-08<br><br> debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01<br> debug: i = 3 thisWeek: 2008-02-01 prevWeek: 2008-02-01<br><br> Quote Link to comment https://forums.phpfreaks.com/topic/93756-why-is-the-output-different-for-this-script/#findComment-480662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.