This forum is now read-only. Please use our new forums at

Objects in PHP Forum

View Course » View Exercise

528 points
Submitted by
Step Wanderer
almost 4 years ago

Problem with 4/10

My code is
class Person {
public $isAlive = "true";
public $firstname;
public $lastname;
public $age;
$teacher = new Person();
$student = new Person();
echo $teacher->isAlive;
but I have got an error:

Oops, try again. It looks as if you didn't echo the value of '$teacher->isAlive. :-(

What is wrong in my code?

1 vote


I had the same problem, but I figured it out.
When you defined public $isAlive, you put quotes around true. Take them out.

1236 points
Submitted by
almost 4 years ago


53fc837752f863a7a8002599_643976555 Elbar Israilov almost 4 years ago

class Classname {
public $prop1 = true;
public $prop2;
public $prop3;
public $prop4;
$obj1 = new Classname();
$obj2 = new Classname();
echo $obj1->prop1;

Use to the following structure

53fc837752f863a7a8002599_643976555 Elbar Israilov almost 4 years ago

In nut shall, clear $teacher and $student variables after function

515dbd8e46a9304d0b0003d5_54679493 Step Wanderer over 3 years ago

Thanks for advice, it works.

53fc837752f863a7a8002599_643976555 Elbar Israilov over 3 years ago

welcome )