Suppose, i have class,
define('property', 'test');
class myClass
{
public $test;
}
$obj=new myClass;
Can i use like this,
$obj->property="value";
Is there any way to achieve this?
Suppose, i have class,
define('property', 'test');
class myClass
{
public $test;
}
$obj=new myClass;
Can i use like this,
$obj->property="value";
Is there any way to achieve this?
Yes, you can as suggested by @Artefacto but make sure that you use constants when you are sure property values won't change !!
The best way to do this is to create an stdClass like class such as:
MyClass
{
public function __set($key,$value)
{
$this->{$key} = $value;
}
}
The you can just use
$Storage = new MyClass;
$Storage->SomeNewVar = "Some New Val";
echo $Storage->SomeNewVar;