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
almost 3 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.

919 points
59f47a0e854be943b60002ef_696126019
Submitted by
Travis Wisecup
almost 3 years ago

1 Comment

5c223dcc8104b22ec076e6cae041b60f?s=140&d=retro Alliancn almost 3 years ago

There is no $ in the $teacher->isAlive