As people have mentioned in the comments, your code is filled with all sorts of errors. What I believe you want is this:
class Person {
function __construct($firstname,$lastname,$age) {
$this->isAlive = true;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person("boring", "12345", 12345);
$student = new Person("boringw", "12345w", 12345);
print_r($teacher);
This code has been tested and it works.
Results:
Person Object ( [isAlive] => 1 [firstname] => boring [lastname] => 12345 [age] => 12345 )
Note: You cannot echo
an object.
2
solved php class error, it wont echo teacher [closed]