Search code examples
phpcodeignitergoogle-auth-library

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

<?php

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??


Solution

  • 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.