how to call Class direct into function

In function direct call parent class and it's functions using the object,

Parent class now, available to inherit using function before we inherited class to class, can call specific function only.


public function function_name(): CLASS_Name { } 
After the creating a object of the Class $object = new CLASS_Name();

call function of class using object

$obA->index();
The Following complete tutorial with guide to how to call parent class to specific child class's function.
<?php
//Limited return type covariance and argument type contravariance
//how to call Class direct into method.
class A {
  
public function index(){
    echo "test1";
}
  
}
class B extends A {}

class Producer {
    public function test(): A {
      $obA = new A();
      echo $obA->index();
      echo "test2";
    }
}
class ChildProducer extends Producer {
    public function method(): B {}
}

$ob = new Producer();
$ob->test();

?>

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...