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

Objects in PHP Forum

View Course » View Exercise

773 points
54e3e4c076b8fe3a21001503_700229069
Submitted by
Abigail Attrell
over 2 years ago

6/10 Parse error: syntax error, unexpected '}', expecting T_STRING on line 22

Hi, I get the above error regarding the ending '}' of my greet function (line 22). Can anyone point out where my code has gone wrong? Thanks!

   <?php
    class Person {
        public $isAlive = true;
        public $firstname;
        public $lastname;
        public $age;
        public function __construct($firstname, $lastname, $age) {
            $this->firstname = $firstname;
            $this->lastname = $lastname;
            $this->age = $age;
        }
        public function greet() {
            return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
            }
    }
    $teacher = new Person("boring", "12345", 12345);
    $student = new Person("exciting", "magick", 12345);
    echo $student->greet();
    echo $teacher->greet();
    ?>

0 votes

permalink

It seems to have fixed itself since I exited and reopened my browser! :-)

773 points
54e3e4c076b8fe3a21001503_700229069
Submitted by
Abigail Attrell
over 2 years ago

2 Comments

51cfb78288634afb2ccf8f6d3ae828e4?s=140&d=retro Sandal1234 over 2 years ago

Hey, did you forget add my name as a property to the object? :-P

I found this error when I submit the code

A5ba1285e8142aa3740cc08378e41d6c?s=140&d=retro Reianna-Bryant about 2 years ago

i pass with this error message, but it does not go away when I take "echo $teacher -> isAlive;
echo $student -> age;" out. I refreshed my browser, and it is still there. What is up?