Advertisement
ujiajah1

object oriented

Aug 20th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.       <title> Introduction to Object-Oriented Programming </title>
  5.       <link type='text/css' rel='stylesheet' href='style.css'/>
  6.     </head>
  7.     <body>
  8.     <div class="malam">
  9.       <p>
  10.       <?php
  11.         // The code below creates the class
  12.         class Person {
  13.             // Creating some properties (variables tied to an object)
  14.             public $isAlive = true;
  15.             public $firstname;
  16.             public $lastname;
  17.             public $age;
  18.            
  19.             // Assigning the values
  20.             public function __construct($firstname, $lastname, $age) {
  21.               $this->firstname = $firstname;
  22.               $this->lastname = $lastname;
  23.               $this->age = $age;
  24.             }
  25.            
  26.             // Creating a method (function tied to an object)
  27.             public function greet() {
  28.               return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
  29.             }
  30.           }
  31.          
  32.         // Creating a new person called "boring 12345", who is 12345 years old ;-)
  33.         $me = new Person('boring', '12345', 12345);
  34.        
  35.         // Printing out, what the greet method returns
  36.         echo $me->greet();
  37.         ?>
  38.         </p>
  39.         </div>
  40.     </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement