This forum is now read-only. Please use our new forums! Go to forums
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
Hi, sorry!
<?php
class Dog {
}
public $numLegs = 4
public $name
function __construct($name){
$this->name = $name;
}
?>
Answer 525aee66f10c60aa13009fa8
0 votes
Hello, would you mind to share your complete code? I think you closed your class before adding the properties and methods.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
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.
I’m not sure where the semicolons went they were there originally! Thanks a lot :)
You are welcome! :-)