unexpected T_NEW on object property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With php5, I'm trying to create an object that has a property that is
another object.  First I have this class:

<?php
class Address {

    public $address1;
    public $address2;
    public $city;
    public $state;
    public $zip;

}
?>

Then I have another class:

<?php
require_once('model/Address.class.php');
class User {
    public $name;
    public $address = new Address();
}
?>

Then if I try to use the user object like this:

<?php
require_once('model/User.class.php');

$user = new User();
$user->name = 'Paul Barry';
$user->address->city = 'Washington';

?>
<?= $user->name ?> lives in <?= $user->address->city ?>

I get this error:

Parse error: syntax error, unexpected T_NEW in /app/model/User.class.php on
line 5

What am I doing wrong?

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux