$$ for classes variables?
Posted: Thu Jan 27, 2011 12:24 pm
Hi all, I'm aware that:
Can this be done with class variables?
Why am I asking? I'm getting an image height and width, I need to find the bigger of the two, so I have $this->bigger and $this->smaller which either equal "height" or "width" so that when I use these variables, I'm using them as follows:
Thanks in advanced!
PS. I know I can do an if statement to get the ratio once and keep going, but this option is a little cleaner and flexible.
Code: Select all
$dog = "cat";
$cat = "dog";
echo $$dog; will echo out "dog"
Code: Select all
protected cat;
protected dog;
public function __construct() {
$this->cat = "dog";
$this-dog = "cat";
}
public function echoOut() {
$this->this->dog; //does not work
}
Why am I asking? I'm getting an image height and width, I need to find the bigger of the two, so I have $this->bigger and $this->smaller which either equal "height" or "width" so that when I use these variables, I'm using them as follows:
Code: Select all
$this->ratio = $this->bigger/$this->smaller; //bigger and smaller are strings that refer to already set variables $this->height, $this->width
PS. I know I can do an if statement to get the ratio once and keep going, but this option is a little cleaner and flexible.