Fatal error: Using $this when not in object context on line 26 error


#1

exercise- Putting It All Together, Part I

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 "hello". $name;
            }
            public function greet()
            {
                return "greet";
            }
        }
        echo $this->name;
       
    ?>
      </p>
    </body>
</html>

#2

You didnt create a object from the class dog.

$dog1 = new dog("Barker");

After that you can echo that:

echo $dog1->bark();

Result should be "hello Barker"