Posts

Showing posts with the label class object

Question: Why should we use class name in another class constructor function in php7?

I was working around oops in php 7 ,in which I pass class name and variable to another class constructor function to access the function of it Like inheritance concept.Let me brief with example Example for passing class name and variable in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constructor   public function __construct(A $a){      $this->a = $a;   }  public function show(){     $user = 'pramodh';     $this->a->execute($user);    } } $b = new B(new A); $b->show(); Out Put : Pramodh Example for passing just variable  in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constru...