This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by james parle
over 10 years

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>

Answer 525b9cc9548c35b18800bebf

1 vote
Best answer

Permalink

Hi, sorry!

<?php 
    class Dog {
    }
    
    public $numLegs = 4
    public $name
    
    function __construct($name){
        $this->name = $name;
    }
    ?> 
points
Submitted by james parle
over 10 years

3 comments

boring12345 over 10 years

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.

james parle over 10 years

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

boring12345 over 10 years

You are welcome! :-)

Answer 525aee66f10c60aa13009fa8

0 votes

Permalink

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

points
Submitted by boring12345
over 10 years