A Method to the Madness Codeacademy PHP Example

A Method to the Madness Codeacademy PHP Example

This one has some flaws, you might get some errors but the website will allow you to move to the next exercice.

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>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
      <p>
        <?php
 
        class Person
            {
                public $isAlive = true;
                public $firstname;
                public $lastname;
                public $age;
 
                public function __construct($firstname, $lastname, $age)
 
                    {
                        $this->$firstname = $firstname;
                        $this->$lastname = $lastname;
                        $this->$age = $age;
                    }
 
                 public function greet()
                    {
                        return "<p>Hello, my name is " . $this->$firstname . " " . $this->$lastname . ". Nice to meet you! :-)";
                    }
 
            }
        $teacher = new Person("boring", "12345", 12345);
        $student = new Person("boring", "12345", 12345);
 
        echo $student->greet();
        echo $teacher->greet();
        ?>
      </p>
    </body>
</html>

Add a comment: