Re: help with classes

From: Date: Tue, 13 Feb 2001 04:11:14 +0000
Subject: Re: help with classes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39331@lists.php.net to get a copy of this message
> Was just wondering how to do the following: > > <?php > class Foo { > > var $bar = $foo; // causes parse error > var $bar = "$foo"; // causes parse error > var $bar = '$foo'; // works but $foo is not evaluated > > } > ?> > > So how does one correctly assign a variable to a variable inside a class withot doing something like: > > var $bar = ''; > $this->bar = $foo; > > Any insight would be much appreciated. I was curious too, so I looked it up. Seems you can't. From http://www.php.net/manual/en/language.oop.php "Note: In PHP 4, only constant initializers for var variables are allowed. Use constructors for non-constant initializers." Hope this helps, Joe

« previous php.general (#39331) next »