Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title> Introduction to Object-Oriented Programming </title>
- <link type='text/css' rel='stylesheet' href='style.css'/>
- </head>
- <body>
- <div class="malam">
- <p>
- <?php
- // The code below creates the class
- class Person {
- // Creating some properties (variables tied to an object)
- public $isAlive = true;
- public $firstname;
- public $lastname;
- public $age;
- // Assigning the values
- public function __construct($firstname, $lastname, $age) {
- $this->firstname = $firstname;
- $this->lastname = $lastname;
- $this->age = $age;
- }
- // Creating a method (function tied to an object)
- public function greet() {
- return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
- }
- }
- // Creating a new person called "boring 12345", who is 12345 years old ;-)
- $me = new Person('boring', '12345', 12345);
- // Printing out, what the greet method returns
- echo $me->greet();
- ?>
- </p>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement