Incorrect page display with arrow notation in PHP

704 views Asked by At

I'm very new to coding in PHP and I've been trying some courses, but I can't seem to figure this out. I wanted to display a page I had to create in a course, but it seemed like the code "broke up" after the first instance of the arrow notation. This is a simplified version of the page (but with the same error).

<html>
    <head>
      <title> Hello World! </title>
    </head>
    <body>
        <p>
            <?php
                class Dog{
                    public $numLegs = 4;
                    public $name;
                    public function __constructor($name){
                           $this->name = $name;
                    }
                    public function greet(){
                        return "Hello! My name is " . $this->name . "!";
                    }
                }

                $Doug = new Dog("Doug");

                echo $Doug->greet();

            ?>
        </p>
    </body>
</html>

Here is the output in Chrome: image

1

There are 1 answers

1
Raghu Goriya On

Here is code,

you have to change constructor to construct on line no 11

and save this file with .php extension

hope you will get the answer

<html>
    <head>
      <title> Hello World! </title>
    </head>
    <body>
        <p>
            <?php
                class Dog{
                    public $numLegs = 4;
                    public $name;
                    public function __construct($name){
                           $this->name = $name;
                    }
                    public function greet(){
                        return "Hello! My name is " . $this->name . "!";
                    }
                }

                $Doug = new Dog("Doug");

                echo $Doug->greet();

            ?>
        </p>
    </body>
</html>