Hi there,
I am just about the correct way of creating object properties/attribute dynamically at run time. I am doing it using the magic methods set() and get(). However, while reading some others code, I have noticed that they are using another way to do the same.
to illustrate other's way, let us say that I have a very basic class as shown below:
class Foo{
public $var1;
public $var2;
function assign_value($key,$value){
$this->$key = $value;
}
}
$foo = new Foo();
$foo->assign_value('var1','test1'); // This is okay becuase var one is already defined in the class
$foo->assign_value('var2','test2'); // This is the same as the first one
$foo->assign_value('var3','test3'); // doing this will create a new attributes called var3 and you can refere to it using $this->var3;
Now, how come var3 was created at run time without using the magic method __set()? Was it called implicitly by the PHP engine to create var3 at run time?
your usual help is appreciated