The detritus of a Button Monkey

24 Feb

Fatal error: Can’t use function return value in write context in….

I have been playing around with comparing string lengths for a time check and kept getting this error:

Fatal error: Can’t use function return value in write context in…….

The code I had been using was:
if (strlen($_POST[‘time’]) = 4) {
$time = TRUE;
$message .= ‘You have entered a time which is fine’;
} else {
$time = FALSE;
}
And it was really bugging me that it didn’t work. Then I realised that the use of a single equals sign was causing the problem, the statement was trying to determine the length of the string but the single equals sign is used to assign a value e.g. $variable = something whereas double equals is a comparator. The working code is:
if (strlen($_POST[‘time’]) == 4) {
$time = TRUE;
$message .= ‘You have entered a time which is fine’;
} else {
$time = FALSE;
}

I perform a separate check to ensure the value is just numbers:

if (ereg(‘[^0-9]’, ($_POST[‘time’]))……..

Leave a Reply

You must be logged in to post a comment.

© 2017 The detritus of a Button Monkey | Entries (RSS) and Comments (RSS)

Design by Your Index - Powered By Wordpress