Suppose i have two classes and i need to call one method from another class if there is a speciific condition is met(i.e: If a gateway is active)
Suppose i have Stripe class and a method in it called createProduct(). I have another class Payment and i want to call that method (createProduct()) from Payment class and there will be no error.
<?php
class Stripe(){
public function __construct(){
if( !$active_stripe ) return;
}
public function createproduct(){
//... Stuffs to create a product
}
}
<?php
class Payment(){
public $stripe;
public function __construct(){
$this->stripe = new Stripe();
}
public function fnCreateproduct(){
$prod = $this->stripe->createProduct();
}
}
Though i am checking is stripe active in __construct fn in first class the createproduct() is still being called.