One way to achieve what you are (I think) referring to, is by returning an object. It goes against the principle of dependency injection, but it's one way to do it.
class MyClassA
{
public function myFunction()
{
return new MyClassB();
}
}
class MyClassB
{
public function execute()
{
return true;
}
}
$class = new MyClassA();
$newObj = $class->myFunction();
echo $newObj->execute();
Another way is to return $this
from the first method. The usage of the above object would work identical in this instance, however you also allow another principle known as method chaining:
class MyClassA
{
public function myFunction()
{
return $this;
}
public function execute()
{
return true;
}
}
$class = new MyClassA();
$sameObj = $class->myFunction();
echo $sameObj->execute();
$class = new MyClassA();
echo $class->myFunction()->execute();