Hi,
I haven't used classes in php before so i created a test class called Person.
<?
class Person
{
var $name;
var $age;
var $haircolor;
var $height;
function Person($name, $age, $haircolor, $height)
{ $this->$name = $name;
$this->$age = $age;
$this->$haircolor = $haircolor;
$this->$height = $height;
}
function birthday()
{ ++$this->$age;
}
function dyeHairColor($newcolor)
{ $this->haircolor = $newcolor;
}
function displayName()
{ return $this->$name;
}
function displayAge()
{ return $this->$age;
}
}
$chuck = NEW Person('chuck', 28, 'brown', 6);
echo '<p>the age of '.$chuck->displayName().' is '.$chuck->displayAge().'</p>';
$chuck->birthday();
echo '<p>the age of '.$chuck->displayName().' is '.$chuck->displayAge().'</p>';
?>
I am doing something wrong because this the output i get
the age of is
the age of 1 is 1
So i guess my constructor is not correct. What am i doing wrong.
Thanks,
Chuck