Posted by Janwillem Borleffs on 09/18/05 01:13
www.douglassdavis.com wrote:
> class MyClass2
> {
> var $x = 2;
> static $y = $x; // error
> }
>
$x does not exist until instantiation, so you should assign $y in the
constructor:
class MyClass2 {
var $x = 2;
static $y;
function __construct() {
$this->y = $this->x;
}
}
The same principle applies to the previous MyClass code, where $this->x
should be replaced by self::$x.
> class MyClass3
> {
> const a = array(1,2); // error
> }
From http://www.php.net/manual/en/language.constants.php:
"Only scalar data (boolean, integer, float and string) can be contained in
constants."
JW
[Back to original message]
|