Q695 Posted May 23, 2013 Share Posted May 23, 2013 This calls the time function $time=timer(); the specific line is: $t2=date('Y M d H:i:s',$time); The function creating $time for organizational purposes is: function timer(){ $time=time(); switch ($_POST['time']) { case 1: //10 minutes $time=$time+600; break; case 2: //30 minutes $time="$time+1800"; break; case 3: //1 hour $time="$time+3600"; break; case 4: //2 hours $time="$time+7200"; break; case 5: //3 hours $time="$time+10800"; break; case 6: //4 hours $time="$time+14400"; break; case 7: //6 hours $time="$time+21600"; break; case 8: //8 hours $time="$time+28800"; break; case 9: //12 hours $time="$time+43200"; break; case 10: //1 day $time="$time+86400"; break; case 11: //2 days $time="$time+172800"; break; case 12: //4 days $time="$time+345600"; break; case 13: //7 days $time="$time+604800"; break; } return $time; } Quote Link to comment https://forums.phpfreaks.com/topic/278305-a-non-well-formed-numeric-value-encountered/ Share on other sites More sharing options...
Barand Posted May 23, 2013 Share Posted May 23, 2013 When you get the error, what does $time contain? Quote Link to comment https://forums.phpfreaks.com/topic/278305-a-non-well-formed-numeric-value-encountered/#findComment-1431735 Share on other sites More sharing options...
kicken Posted May 23, 2013 Share Posted May 23, 2013 case 3: //1 hour $time="$time+3600"; break; Because you used quotes around the expression, no math will be performed. At the end $time will contain (assuming $time originally contained 12345): 12345+3600, rather than 15945 as you intended. The value 12345+4600 is an invalid number and thus cannot be passed to the date function. So, remove all your quotes so that the math is performed and you get a real number. Unless you want something to be treated as a string, do not quote it. Quote Link to comment https://forums.phpfreaks.com/topic/278305-a-non-well-formed-numeric-value-encountered/#findComment-1431738 Share on other sites More sharing options...
Solution Q695 Posted May 23, 2013 Author Solution Share Posted May 23, 2013 echo $time; Outputs things like 1369275959, 1369276047, 1369276068, ... Because you used quotes around the expression, no math will be performed. At the end $time will contain (assuming $time originally contained 12345): 12345+3600, rather than 15945 as you intended. The value 12345+4600 is an invalid number and thus cannot be passed to the date function. if you use the double quotes it treats it like a " echo statement, not a ' echo statement. Somehow when I went to dinner it solved itself. Quote Link to comment https://forums.phpfreaks.com/topic/278305-a-non-well-formed-numeric-value-encountered/#findComment-1431740 Share on other sites More sharing options...
DavidAM Posted May 24, 2013 Share Posted May 24, 2013 No. When you use double quotes, the variable name is replaced by the string representation of the variable's value. Math is not performed, functions are not called. It is simply a way to put a variable value into a string. <?php $t = time(); $t = "$t+3600"; var_dump($t); date('r', $t); ?> # Results string(15) "1369417662+3600" Notice: A non well formed numeric value encountered in /home/mad/logs/- on line 5 - PHP 5.2.6 Quote Link to comment https://forums.phpfreaks.com/topic/278305-a-non-well-formed-numeric-value-encountered/#findComment-1432102 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.