Re: variable variables in classes
| From: | Matt McClanahan | Date: | Tue, 05 Sep 2000 02:47:33 +0000 |
| Subject: | Re: variable variables in classes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-15212@lists.php.net to get a copy of this message | ||
On Tue, 5 Sep 2000, news.php.net wrote:
> Problem:
>
> How do I use variable variables in a class?
> For instance:
>
> class example {
>
> var $test = Hello;
>
> function output() {
> printf($this->{$this->test});
>
> }
> }
>
> $var = new example;
>
> $var->output(); \\ It doen'tt work!
Ought to work fine. Did you define a class variable $Hello? If
$this->Hello isn't there, $this->{$this->test} won't get you much.
This works for PHP 4.0.1pl2:
<?
class me
{
var $test = 'foof';
var $foof = 'Greetings';
function output() { echo $this->{$this->test}; }
};
$cl = new me();
$cl->output();
?>
Matt