Reputation: 693
i'm doing the Property Panic (2) from Using Objects in PHP course (Codeacademy.com), but I have this error. Here's my code :
<!DOCTYPE html>
<html>
<head>
<title>Reconstructing the Person Class</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<?php
class Person{
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}
public function __construct($firstname, $lastname, $age){
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
$teacher = new Person("boring","12345",12345);
$student = new Person("a","b",23);
echo $teacher->age;
?>
</p>
</body>
Where does it come from? Thanks
Upvotes: 2
Views: 463
Reputation: 219804
Your constructor belongs inside your class:
class Person{
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname, $lastname, $age){
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
Upvotes: 14