Assume you have several arbitrary classes like below:
class Foo
{
$foovar;
public function __construct()
{
$foovar = "Foo";
}
public function getFoo()
{
return($foovar);
}
}
class Bar
{
$F;
public function __construct()
{
$F = new Foo();
}
}
My question is is it possible to write something like the following
$B = new Bar();
echo($B->F->getFoo());
Like I said in my previous question, I come from a strong Java background know you can link variables together System.out.println() to call other objects methods. I’d like to know if this is possible in PHP
Yes you’re absolutely correct, please see this example.
Some other comments
$this->foovarto work with class members (unless static, in which case it’sself::$foovarClass members must also have their access type specifed, for example
public $foovar;.Why you’re moving from Java to PHP is beyond me, but good luck 🙂