Putting It All Together, Part I Codeacademy PHP Example

Putting It All Together, Part I Codeacademy PHP Example

This one is very easy. Just create a basic class, add a construct and that’s all.

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
<!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;   
                    }
            }
 
        ?>
      </p>
    </body>
</html>

Add a comment: