Syntax error - but I get a "way to go!" message


#1

Below is my code. When I run it, it passes.
However, on the side it shows a syntax error like this:
Parse error: syntax error, unexpected T_PUBLIC on line 17

<!DOCTYPE html>
<html>
	<head>
	  <title> Practice makes perfect! </title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
      <p>
              <?php
        class Dog{
            public $numLegs = 4;
            public $name;
            
        public function __constructor($name){
            $this->name = $name;
            
        public function bark(){
            return "Woof!";
            
        public function greet(){
            return "The dog's name is ".$this->name." and it bites!";
                        }
                    }
                }
            }
            
        $dog1 = new Dog(){
            $this->name = "Barker";
                }
        
        $dog2 = new Dog(){
            $this->name = "Amigo";
                }
        
        echo $dog1->bark();
        echo $dog2->greet();
        
       ?>
       ?>
      </p>
    </body>
</html>

Anyone know if this is abug from codecademy's side, or if there is a syntax error in my code (maybe it should not have gone through)?


#2

First of all
public function __constructor // wrong
it should be public function __construct

Adding public methods (in a class):

public function meth1() {
return "Some text ";
}
public function meth2() {
return "Some text " . $this->name . " some further text";
}

so you forgot to close

public function __constructor($name){
$this->name = $name;
// here(see your code)

do the same for the rest.
next
Creating an instance (outside):
$obj1 = new Classname($prop2);

you should do

$dog1=new Dog("Barker");

but you did

$dog1 = new Dog(){
$this->name = "Barker";
}

that is wrong.

i hope now you have understand :slight_smile:


#3

Wow..it all makes perfect sense.
Thank you so much for your response. I have made the necessary fixes. :slight_smile: