Putting It All Together, Part II Codeacademy PHP Example

Putting It All Together, Part II Codeacademy PHP Example

A tricky one. Has lots of old syntax, but it’s not easy to remember it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!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()
                    {
                        echo "Woof!";   
                    }
                public function greet()
                    {
                        return "Hello my '.$this->name.', my friend";   
                    }
            }
 
            $dog1 = new Dog("Barker");
            $dog2 = new Dog("Amigo");
 
            echo $dog2->greet();
 
 
        ?>
      </p>
    </body>
</html>

Add a comment: