How to pass a parameter into a PHP class constructor?

Hello,

I am using API class into my model class. In that API class need to pass constructor argument of apikey.

Need to pass arg like $obj = new \Apiclass($apikey);

I try to using create class via __construct(). in this case how to pass the apikey argument to the api calss.

public function __construct(
\Class\path $asname,
\Apiclass $api
)
{

}

Your syntax is right:

 $obj = new \Apiclass($apikey);

2 posts were split to a new topic: Do I need to call a third-party class constructor “based on DI method”?