Wednesday, April 30, 2008

PHP Error: function return in write context

I was presented with a strange error in PHP today,

Fatal error: Can't use function return value in write context in /var/www/script.php on line 31


This is the code I was using on line 31.

$email = empty(ini_get('sendmail_from')) ? $default : ini_get('sendmail_from');


The problem was with the call to ini_get being within a call to empty.

To get rid of the error, I needed to check for empty values returned from ini_get differently.

$email = ini_get('sendmail_from') == '' ? $default : ini_get('sendmail_from');

No comments: