My question is very simple, I saw this code in a class:
class controller_activity {
function __construct($args) {
//the variable template is not defined or what happen??
$this->template = new Template('activity');
}
.......
Usually I see the declaration of variables in a class like “public $template” or similar, but this case, is the same that if I define those variables as usual?, can I add variables in this way directly?, without defining them before?, is it recomendable?
No, the definition is missing.
get_object_varswill show them, butget_class_varswon’t.Yes, that is possible. They will be publicly visible.
Yes, without defining them before. They will be publicly visible.
That depends. Normally not, but there are exceptions to this rule.