I have initialized a new instance of a library in the __construct(){} method of a PHP class and equated it to a variable,
but now I want to use this variable to access methods of the library inside another function but PHP is not allowing me do that.
class Demo
{
public function __construct()
{
parent::__construct(new PaymentModel);
$this->api = new Api(config("razorpay", "key_id"), config("razorpay", "key_secret"));
}
public function createOrder()
{
$order = $api->order->create();
echo '<pre>';
var_dump($order); die;
}
}
I looked at the __construct documentation and some other answers here on stack overflow but all they did was confuse me more than helping me out.
Please help me figure this out as I am a starter myself in tech.