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

Objects in PHP Forum

View Course » View Exercise

1089 points
2cd1c3c498834bec23907b39e5d274fb?s=140&d=retro
Submitted by
filkuzmanovski
over 2 years ago

4/10 passed but something is off with the code

Parse error: syntax error, unexpected TVARIABLE, expecting TFUNCTION on line 11
//Code below
<?php
class Person {
$teacher = new Person();
$student = new Person();
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}
echo $teacher->$isAlive;
?>


0 votes

permalink

To create your $teacher and $student Person objects you declare them outside of the Person class like so.

class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}

$teacher = new Person();
$student = new Person();

echo $teacher->$isAlive;

I think that should be how 4/10 is solved, but for some reason it doesn't recognize the properties after $isAlive.

853 points
E7df1c83b3ca0f191a4e464979142518?s=140&d=retro
Submitted by
Hunar
over 2 years ago

1 Comment

5c223dcc8104b22ec076e6cae041b60f?s=140&d=retro Alliancn over 2 years ago

There is no $ in the $teacher->isAlive