Advertisement
ujiajah1

OOP

Aug 20th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title>Class and Object Methods</title>
  4.   </head>
  5.   <body>
  6.     <p>
  7.       <?php
  8.         class Person {
  9.           public $isAlive = true;
  10.          
  11.           function __construct($name) {
  12.               $this->name = $name;
  13.           }
  14.          
  15.           public function dance() {
  16.             return "I'm dancing!";
  17.           }
  18.         }
  19.        
  20.         $me = new Person("Shane");
  21.         if (is_a($me, "Person")) {
  22.           echo "I'm a person, ";
  23.         }
  24.         if (property_exists($me, "name")) {
  25.           echo "I have a name, ";
  26.         }
  27.         if (method_exists($me, "dance")) {
  28.           echo "and I know how to dance!";
  29.         }
  30.       ?>
  31.     </p>
  32.   </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement