Archive

Archive for the ‘PHP’ Category

PHP Fatal error: Can’t use method return value in write context

November 19th, 2010 1 comment

I came across the following error recently when trying to evaluate in PHP whether a value was empty:

Fatal error: Can't use method return value in write context

It turns out that the PHP empty function cannot accept the return value from another function so you have to first define the variable before passing it to the empty() function.

// will generate a fatal error
empty(nl2br($string));
empty($obj->getSomeValue());

// will work
$val = nl2br($string);
$val = $obj->getSomeValue();
empty($val);

Alternatively, you can use the following function instead:

/**
 * Determines whether a variable is considered to be empty,
 * additionally accepts returned values from functions
 *
 * @param mixed	$val	The value to evaluate
 * @return boolean
 */
function empty_return($val) {
	return empty($val);
}

// example
empty_return(nl2br($string));
Categories: PHP Tags:

Automatically Collapse FirePHP Responses

November 3rd, 2010 1 comment

FirePHP is a Firefox extension that allows you to log directly to the Firebug console from PHP. This is great for AJAX applications because you can debug your server side scripts without interferring with the responses.

Each script that returns a FirePHP log will generate it’s own group in the Firebug console which is expanded by default which means if you are logging a lot of data on the server side (such as database queries) then there will be a lot of data displayed in the console which you may not want to see all the time.

My solution to this was to edit the FirePHP extension so that each script response is collapsed automatically. You can then click a response to expand it if you want to view more details. Read more…

Categories: Firefox, Javascript, PHP Tags: