troubleshooting Question

How to fix "Using $this when not in object context" in php error log?

Avatar of Dima Iva
Dima Iva asked on
PHP
2 Comments1 Solution18 ViewsLast Modified:
I have an OJS journal running on Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11.

In order to fix a "non-static method PKPApplication::getRequest()" error:

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 ended up adding the word "statitc" in two files:

on line 237 in C:\xampp\htdocs\journal\lib\pkp\classes\core\PKPApplication.inc.php

233:    /**
234:     * Get the request implementation singleton
235:     * @return Request
236:     */
237:    public static function getRequest() {
238:       $request =& Registry::get('request', true, null); // Ref req'd
239: 
240:       if (is_null($request)) {
241:          import('classes.core.Request');
242: 
243:          // Implicitly set request by ref in the registry
244:          $request = new Request();
245:       }
246: 
247:       return $request;
248: 


and on line 143 in C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php

138:    /**
139:     * Return PKP request object
140:     *
141:     * @return PKPRequest
142:     */
143:    public static function getRequest() {
144:       return $this->_request;
145:    }

I now have the following error in php_error_log:

Slim Application Error:
Type: Error
Message: Using $this when not in object context
File: C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php
Line: 144

The whole error is here:
Slim Application Error:
Type: Error
Message: Using $this when not in object context
File: C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php
Line: 144
Trace: #0 C:\xampp\htdocs\journal\lib\pkp\classes\security\authorization\internal\ApiAuthorizationMiddleware.inc.php(39): APIHandler::getRequest()
#1 C:\xampp\htdocs\journal\lib\pkp\classes\security\authorization\internal\ApiAuthorizationMiddleware.inc.php(72): ApiAuthorizationMiddleware->_authorize(Object(Slim\Http\Request))
#2 [internal function]: ApiAuthorizationMiddleware->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Slim\App))
#3 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(ApiAuthorizationMiddleware), Array)
#4 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Slim\App))
#5 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Slim\App))
#6 C:\xampp\htdocs\journal\lib\pkp\classes\security\authorization\internal\ApiCsrfMiddleware.inc.php(46): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#7 [internal function]: ApiCsrfMiddleware->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#8 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(ApiCsrfMiddleware), Array)
#9 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#10 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#11 C:\xampp\htdocs\journal\lib\pkp\classes\security\authorization\internal\ApiTokenDecodingMiddleware.inc.php(82): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#12 [internal function]: ApiTokenDecodingMiddleware->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#13 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(ApiTokenDecodingMiddleware), Array)
#14 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#15 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#16 C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php(68): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#17 [internal function]: APIHandler->{closure}(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#18 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#19 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#20 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#21 C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php(127): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#22 [internal function]: APIHandler->{closure}(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#23 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#24 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#25 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#26 C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php(132): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#27 [internal function]: APIHandler->{closure}(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#28 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#29 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#30 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#31 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#32 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\App.php(392): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(APIResponse))
#33 C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php(124): Slim\App->process(Object(Slim\Http\Request), Object(APIResponse))
#34 [internal function]: APIHandler->{closure}(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#35 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#36 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#37 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#38 C:\xampp\htdocs\journal\lib\pkp\classes\handler\APIHandler.inc.php(132): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#39 [internal function]: APIHandler->{closure}(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#40 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#41 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#42 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(APIResponse), Object(Closure))
#43 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(APIResponse))
#44 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\App.php(392): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(APIResponse))
#45 C:\xampp\htdocs\journal\lib\pkp\lib\vendor\slim\slim\Slim\App.php(297): Slim\App->process(Object(Slim\Http\Request), Object(APIResponse))
#46 C:\xampp\htdocs\journal\lib\pkp\classes\core\APIRouter.inc.php(115): Slim\App->run()
#47 C:\xampp\htdocs\journal\lib\pkp\classes\core\Dispatcher.inc.php(143): APIRouter->route(Object(Request))
#48 C:\xampp\htdocs\journal\lib\pkp\classes\core\PKPApplication.inc.php(281): Dispatcher->dispatch(Object(Request))
#49 C:\xampp\htdocs\journal\index.php(68): PKPApplication->execute()
#50 {main}
View in rendered output by enabling the "displayErrorDetails" setting.

I understand that I probably needed to add "static" higher up in the APIHandler.inc.php file, but I am not sure where.  And maybe I don't need "static" in the PKPApplication.inc.php?  I am attaching the file referred in the error.  Could someone point me in the right direction?

APIHandler.inc.php

Many thanks in advance!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros