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

Objects in PHP Forum

View Course » View Exercise

316 points
52555460548c353b14002792_460418154
Submitted by
james parle
over 3 years ago

Parse error: syntax error, unexpected T_PUBLIC on line 13 - but code works, why?

Below is my code, line 13 is "public $numLegs = 4". Any ideas why I am getting the error mentioned in the title? The code has passed fine but it's bugging me (no pun intended).

Thanks!

    public $numLegs = 4;
    public $name;

    function __construct($name){
        $this->name = $name;
    }
    ?>    <!-- Your code here -->
      </p>
    </body> </html>

1 vote

Best answer

permalink

Hi, sorry!

<?php 
    class Dog {
    }

    public $numLegs = 4
    public $name

    function __construct($name){
        $this->name = $name;
    }
    ?> 

316 points
52555460548c353b14002792_460418154
Submitted by
james parle
over 3 years ago

3 Comments

5154c6cf115b457ac9000021_667301409 boring12345 over 3 years ago

Okay, you have to put the properties and the __construct() method into the body of the class. And don't forget the semicolons after defining your properties.

52555460548c353b14002792_460418154 james parle over 3 years ago

I'm not sure where the semicolons went they were there originally! Thanks a lot :)

5154c6cf115b457ac9000021_667301409 boring12345 over 3 years ago

You are welcome! :-)


0 votes

permalink

Hello,
would you mind to share your complete code?
I think you closed your class before adding the properties and methods.

3108 points
5154c6cf115b457ac9000021_667301409
Submitted by
boring12345
over 3 years ago