I’m new to OOP and I’m using twig.
However I’ve two classes ( different files ) and I want to call some functions from for example classA.php into classB.php.
Now I’m creating a new instance inside classB functions each time I want to call functions from classA.
My question now is.. is it possible to create a public variable in classB to create instance then just call that variable inside any function ?
For example:
classB.php
<?php
use AppModelsClassA
class ClassB extends Base
{
public $classA = new ClassA();
public function test
{
return $classA->functionA();
}
}
I’m trying the above, and I got the following error:
Fatal error: Constant expression contains invalid operations
I don’t know if it’s possible or correct, I need your advise.
Thanks in advance.