PHP compiler generate fatal error if you use function return value in read/write context. Although this is not applicable for all PHP supported function but PHP function like empty does not support use of the function in this way. In other words, php empty function cannot check the return value of a function or method. It can only check variables so use only variable inside empty function. Any other function or expression inside empty function will lead to generate fatal error.

Example Problem Solution:

Wrong
if(empty(trim($testimony))) echo “Empty”; else echo “Not Empty”;

Correct
$testimony = trim($testimony);
if(empty($testimony)) echo “Empty”; else echo “Not Empty”;

Wrong
if(empty($bobj->get_results(‘post’)) { // Processing Code }

Correct
$tmp = $bobj->get_results(‘post’);
if(empty($tmp)) { // Processing Code }

Written by Hemant Patel

Hemant, hailing from Bhopal, Madhya Pradesh, India, is a web developer and occasional blogger passionate about exchanging ideas and addressing problems in his coding journey.