Hi all,
If I have a class (like below) and in a function I set a variable (below:$this->example) but I havent declared the variable at the top of the class (e.g var $example;) where and how can I use this variable? I tried using it straight away in another function but it didn't work (I guess I could have made a mistake but it worked after I declared it in the top of the class)
I have seen this in Symfony for setting variables that you can use in the view and also I came accross it in Phorms to name a couple of examples.
Sorry if this is obvious, I would just like to understand how I can use these variables, including getting the name of the variable(e.g $this->example, by name I mean "example").
class ExampleClass{
var $another_var;
function __construct($data){
$this->example = $data;
$this->another_var = $data;
}
function exampleFunction(){
$test = $this->example; //this doesnt work
$another_test = $this->another_var; //this obviously does
}
}
Any help would be much appreciated
Regards
Luke
EDIT: (from my reply to DrColossus)
I want to be able to set any variable name in a function and in another function grab any variables set with there name.For example in Symfony I can set $this->completly_random_name = $x in an action class function, then in the view I can use $completly_random_name. There is no way that symfony has set every possible combination of variable names in the top of the parent class.