Lots of PHP Deprecated: Non-static method

I’m getting lots of those errors on my cron jobs, anything I can do about them?

PHP Deprecated:  Non-static method Core::removeBaseUrl() should not be called statically in /usr/home/luizborges/www/public_html/plugins/generic/usageStats/UsageStatsLoader.inc.php on line 767
PHP Deprecated:  Non-static method Core::_getBaseUrlAndPath() should not be called statically in /usr/home/luizborges/www/public_html/lib/pkp/classes/core/Core.inc.php on line 231
PHP Deprecated:  Non-static method Core::removeBaseUrl() should not be called statically in /usr/home/luizborges/www/public_html/plugins/generic/usageStats/UsageStatsLoader.inc.php on line 767
PHP Deprecated:  Non-static method Core::_getBaseUrlAndPath() should not be called statically in /usr/home/luizborges/www/public_html/lib/pkp/classes/core/Core.inc.php on line 231

While a lot of work has recently been done to clean up some of the legacy coding style which leads to these warnings, there is still work to be done.

These warnings (PHP Deprecated, PHP Strict Standards) are helpful to developers, but for production purposes, it is best to turn them off:

The “deprecated” error messages were bothering me too. This one, in particular, was appearing thousands of times each day:

PHP Deprecated: Non-static method PKPApplication::getRequest() should not be called statically in C:\xampp\htdocs\journal\plugins\generic\customHeader\CustomHeaderPlugin.inc.php on line 128

I wanted to suppress these messages in the php_error log, but experts suggested that it would be like sweeping the problem under the rug and encouraged me to try and fix it.

The error message was saying that on line 128 in CustomHeaderPlugin.inc.php I had this:

$request = Application::getRequest();

which had to have the word “static” added to function definition.

In the Application class getRequest was declared like this:

class Application {
public function getRequest() {
// …
}
}

while it should be declared like this:

class Application {
public static function getRequest() {
// …
}
}

The problem was that the function was not declared in CustomHeaderPlugin.inc.php. Turned out that I needed to edit htdocs\journal\lib\pkp\classes\core\PKPApplication.inc.php.

In there, I added “static” to the following line and the “deprecated” errors stopped!

public static function getRequest() {

That’s the function and if in the future it could be touched up centrally by OJS friends, it could save some users some trouble :slight_smile:

/**
 * Get the request implementation singleton
 * @return Request
 */
public static function getRequest() {
	$request =& Registry::get('request', true, null); // Ref req'd

	if (is_null($request)) {
		import('classes.core.Request');

		// Implicitly set request by ref in the registry
		$request = new Request();
	}

	return $request;
}