Reference: Am using Slim Framework to develop Rest API application. Problem: While doing so, used static functions. However, one of the functions that were called from my api code, threw an error "Using $this when not in object context". Since I cannot change the code being called which is generating the issue, I need to change my code.
Sample Code before change: $app->post($mer_token_endpoint, get_token);
The rest of the code is fine, except the issue of $this. Wherever it is not called, those APIs work fine.
Now I changed the code to:
class Token {
public function get_token(Request $request, Response $response, array $args) {
.... code ....
}
}
$TokenObj = new Token();
$app->post($token_endpoint, $TokenObj->get_token);
How do I pass the reference of the function get_token declared in the class Token in the function post ?