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

548 points
51f4c9a19c4e9dff9f006775_441989819
Submitted by
Vu Nguyen Viet
almost 5 years ago

[solved]Parse error: syntax error, unexpected T_PUBLIC on line 14

The code passed but it threw an error! need help

Parse error: syntax error, unexpected T_PUBLIC on line 14

here's my code

        <!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 __construct($name){
            $this->name = $name;
        }
        public function bark(){
            return "Woof!";
        }
        public function greet(){
            return "Bow wow my name is ". $this->name . "bow wow!!";
        }
        $dog1 = new Dog("Barker");
        $dog2 = new Dog("Amigo");
        echo $dog1->bark();
        ?>
      </p>
    </body>
</html>

Thank you in advance

UPDATE:
Move methods into class

            <!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 __construct($name){
                $this->name = $name;

            public function bark(){
                return "Woof!";
            }
            public function greet(){
                return "Bow wow my name is ". $this->name . "bow wow!!";
            }
            }
            $dog1 = new Dog("Barker");
            $dog2 = new Dog("Amigo");
            echo $dog1->bark();
            ?>
          </p>
        </body>
    </html>

1 vote

permalink

Hello,
your methods aren't part of your class.

3108 points
5154c6cf115b457ac9000021_667301409
Submitted by
boring12345
almost 5 years ago

2 Comments

51f4c9a19c4e9dff9f006775_441989819 Vu Nguyen Viet almost 5 years ago

Thank you how silly I am :)

5154c6cf115b457ac9000021_667301409 boring12345 almost 5 years ago

You are welcome! :-)