Hi I have a class defined as below. I want to assign the value of myvar to myvar1. But it gives me error
class Common {
public static $myvar = 'abcd'; public static $myvar1 = $myvar."efgh"; }
Can someone help.
Thanks
You cant use a class property and assign it to another, unless you have a method to do it for you.
Can u give me an example Thanks
Im going to assume your using PHP 5 as your using public.
class Common { public static $myvar = 'abcd'; private $myvar1; public function setMyVar1($text) { $this->myvar1 = $this->myvar . $text; } }
Thanks 🙂
Please mark the thread as resolved...here's a generic "set variable function" for any class:
function setVar($var, $value) { $this->$$var = $value; }
Pass it the name of the variable, without a $ (dollar) sign. Or pass me $100 😃