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

Objects in PHP Forum

View Course » View Exercise

269 points
1458bf1474fccb99f6bef36c5669da37?s=140&d=retro
Submitted by
ConDug
over 2 years ago

Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 18

As in Exercise 5 of "Using Objects in PHP" there seems to be an error which is here no matter what I change. This is the base error I get get when the exercise loads for the first time.
On exercise 5, I was able to progress even though I had a similar error which was related to my first this->firstname = $firstname; line of code. Anyone able to explain this?


0 votes

permalink

if you don't mind posting your code? it's easier to see what you did there and it did be easier to explain what you had done wrong =) FYI, read on previous chapter, it did explain that sentences what it meant and it's purpose of way.

779 points
551612e39113cb3314000781_225067205
Submitted by
ethanqwk
over 2 years ago

2 Comments

8e0d8e0e893faba8d1f4356f504e3b6e?s=140&d=retro code2learn over 2 years ago

I get that issue in line 20, it has some thing to do with the (public function __construct($firstname, $lastname, $age)) please let me know what I have wrong.

<!DOCTYPE html>


Reconstructing the Person Class




<!-- Your code here -->
<?php

    class Person {
        public $isAlive = true;
        public $count = 3;
        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("david", "dave", 100);
    echo $student->age;
    echo greet($teacher);
    echo greet($student);
    ?>

  </p>
</body>

(other than that progressing nicely thanks!)

551612e39113cb3314000781_225067205 ethanqwk over 2 years ago

HI code2learn, Just to revise back those previous lesson that you might been missing out or skipped through. Brackets, Parenthesis, Coma, Semicolons are very sensitive and critical. To guide you better on this. this->firstname = $firstname; and $this->firstname = $firstname; are completely different meaning and an error. The missing & sign on the above comparison, it's common to be found in most method declaration way. It will be hard for me to explain but once you finish up the lesson you might understand that $this->firstname = $firstname; holds a part of the method declaration way.Let me know if you find me wrong since I'm partly learning as well.