0

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

Danish Ali
  • 2,354
  • 3
  • 15
  • 26

3 Answers3

1

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.

MihanEntalpo
  • 1,952
  • 2
  • 14
  • 31
1

You can't able to create object for abstract class that is the error .. try some thing like this

<?php
use rapidweb\googlecontacts\helpers\GoogleHelper;
class Chatlibrary extends GoogleHelper {

function linkauth(){

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

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

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

    return $authUrl;
}
Shibon
  • 1,552
  • 2
  • 9
  • 20
  • 1
    @AgustinoWhickey reffer this link to see more about abstract class https://stackoverflow.com/questions/2558559/what-is-abstract-class-in-php – Shibon Feb 07 '19 at 05:04
1

FYI:

We cannot create the instance of abstract classes. To use methods of abstract class we have to extend the abstract class in another class. In your case, you are trying to instantiate the abstract class as

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

This is not allowed. You can simply extend the above class in Chatlibrary class as answered by MihanEntalpo and Shibon and you have access to all the methods of the abstract class.

For more information about the abstract class, you can refer to this PHP manual.

Rohit Ghotkar
  • 803
  • 5
  • 17