Jump to content

A non well formed numeric value encountered


Q695

Recommended Posts

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;
}

 

		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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.