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

Objects in PHP Forum

View Course » View Exercise

514 points
515dbd8e46a9304d0b0003d5_54679493
Submitted by
Step Wanderer
about 3 years ago

Problem with 4/10

My code is
<?php
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

permalink

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
Fe986d8406cb8d594f00e3510bcd323c?s=140&d=retro
Submitted by
MeghaDalal
about 3 years ago

4 Comments

53fc837752f863a7a8002599_643976555 Elbar Israilov about 3 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 about 3 years ago

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

515dbd8e46a9304d0b0003d5_54679493 Step Wanderer over 2 years ago

Thanks for advice, it works.

53fc837752f863a7a8002599_643976555 Elbar Israilov over 2 years ago

welcome )