Re: unexpected T_NEW on object property

From: Date: Sat, 22 Apr 2006 02:08:20 +0000
Subject: Re: unexpected T_NEW on object property
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-234543@lists.php.net to get a copy of this message
M. Sokolewicz wrote:
Jochem Maas wrote:
Paul Barry wrote: ..
Then I have another class: <?php require_once('model/Address.class.php'); class User {
    public $name;
    public $address = new Address();
this is wrong. you can define the property in the class with a constant or scalar value (i.e. literal string, numeric value or an array) but not a return value of a function or a 'new' object.
just to nag, an array is not a scalar value. However, you're correct on this. Properties can only be defined in the class with constant values (this does not mean they have to be constants! The values they get just have to be fixed, and not determined during runtime.)
IC - spot the self taught idiot :-) (that's me btw)

« previous php.general (#234543) next »