Reputation: 97
i'm using smarty as a temeplete engine and i have one very big class and other classes extended to it and in each sub class i using
function __construct(mainclass &$mainclass) {
$this->mainclass= & $mainclass;
}
to use the main class vars in the sub class
and in the end of my code is
$this->assign( 'mainclass' , $mainclass);
which assign my db connection and all other things
my question is "is that wrong or true?"
Upvotes: 0
Views: 62
Reputation: 2561
Rather than doing this you can also extend that class. and you can use all class variables and functions of that file using $this keyword.
main.php
class main_class{
private $var = 'a';
}
sub.php
class sub_class extends main_class{
echo $this->var;
}
I think it should work for you.
Upvotes: 1