Blemish in WordPress plugin “FireStats”


FireStats
FireStats

Actually I didn’t want to write about this at all, but now I see that some people googled for the very same error message that I recently got from FireStats as well:

Wrong parameter count for debug_backtrace()

Obviously Google combed through my site just at the time when it was littered with that unlovely error message, and thereby a couple of searchers wound up here – who probably left soon, because there is really nothing to find about that subject here. :)
So in order to not disappoint future guests, I will quickly explain how I got rid of that error again.

Ganz am Ende der Datei firestats/php/utils.php befindet sich folgende Funktion:

function fs_called_by($function)
{
	$bt = debug_backtrace(false);
	for($i = count($bt)-1;$i >= 0;$i--)
	{
		$frame = $bt[$i];
		if ($frame['function'] == $function) return true;
	}
	return false;
}

Die Funktion debug_backtrace() hatte ursprünglich gar keine Parameter. Erst seit PHP 5.2.5 ist es möglich, der Funktion einen Boolean-Wert, also true oder false, zu übergeben:”debug_backtrace(php.net)”:http://www.php.net/manual/de/function.debug-backtrace.php . Wenn man nun aber auf seinem Server ein älteres PHP laufen hat als Version 5.2.5 – was heutzutage durchaus noch oft vorkommt – dann kennt er natürlich nur eine Funktion debug_backtrace() ohne Parameter. Und deshalb streikt er dann auch, wenn FireStats versucht, der Funktion einen Wert zu übergeben.

Die Lösung ist simpel, man muß den Parameter einfach löschen – ich weiß gar nicht, warum er da überhaupt steht, er wird ja sowieso nicht gebraucht. Also einfach Zeile 1042 ändern in:

$bt = debug_backtrace();

At the very end of the file firestats/php/utils.php, you find the following function:

function fs_called_by($function)
{
	$bt = debug_backtrace(false);
	for($i = count($bt)-1;$i >= 0;$i--)
	{
		$frame = $bt[$i];
		if ($frame['function'] == $function) return true;
	}
	return false;
}

Originally, the function debug_backtrace() had no parameters at all. Only since PHP 5.2.5 it is possible to pass a Boolean value, i. e. true or false, to the function:”debug_backtrace(php.net)”:http://www.php.net/manual/en/function.debug-backtrace.php . Now, if your server is running a PHP version prior to 5.2.5 – which still occurs quite often these days – it will only know a function debug_backtrace() without any parameters. And that causes it to fail as soon as FireStats tries to pass a value to the function.

The solution is simple, you only have to delete the parameter – I don’t know why it’s there anyway, it isn’t needed at all. So, just change line 1042 into:

$bt = debug_backtrace();

One response to “Blemish in WordPress plugin “FireStats””

Leave a Reply

Your email address will not be published. Required fields are marked *