Saturday 24 August 2019

php - Cannot instantiate abstract class in library codeigniter



I'm just installed a google auth SDK. I want to apply it in CodeIgniter library.



Here is my library





class Chatlibrary{

function linkauth(){

$customConfig = (object) array(
'clientID' => 'myIdGoogle',
'clientSecret' => 'MySecretId',
'redirectUri' => 'MyRedirectUri',
'developerKey' => ''

);

require_once 'autoload.php';

$google = new rapidweb\googlecontacts\helpers\GoogleHelper;

$client = GoogleHelper::getClient($customConfig);

$authUrl = GoogleHelper::getAuthUrl($client);


return $authUrl;
}


I just want to call rapidweb\googlecontacts\helpers\GoogleHelper correctly.



My code above will show an error




"Message: Cannot instantiate abstract class rapidweb\googlecontacts\helpers\GoogleHelper".





Anyone can help me??


Answer



Just remove the line $google = new rapidweb\googlecontacts\helpers\GoogleHelper;



This is the place where you try to instantiate GoogleHelper, and you don't use $google variable later, but calling static methods of GoogleHelper. So, you don't need to instantiate it at all.



If it doesn't help, you can do following:




1) Create your own class



class MyGoogleHelper extends rapidweb\googlecontacts\helpers\GoogleHelper
{
//...
}


2) Use it instead of rapidweb\googlecontacts\helpers\GoogleHelper




3) If you'll get errors about some non-implemented methods of the class, implement whem, even empty ones would be fine for the start.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...