I need to use static methods with __construct()
method to instantiate the Client
object but the as far as I know there is no way to use the __construct()
since the object is not instantiated when using static methods.
I thought I can use an init method.
class API
{
static $client;
public static function init()
{
$settings = [
'username' => 'user1',
];
self::$client = new Client($settings);
}
public static function foo( )
{
self::$client->action('Foo text');
}
}
API::init();
Then I can load the above class in other places and do the below.
API::foo();
My Questions:
- Is there anything wrong with the way I wrote the class?
- Does the above codes cause performance issue?
- Is there any better way?
Any help is appreciated.