Stratician

PHP User Accounts

Feb 1st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. //Main Account System Class
  4.  
  5. abstract class Accounts {
  6.  
  7.     protected $name;
  8.     protected $email;
  9.     protected $hasPremium;
  10.     protected $openTrades;
  11.     protected $completedTrades;
  12.  
  13.     public function __construct($name, $email, $hasPremium = false)
  14.     {
  15.         $this->name = $name;
  16.         $this->email = $email;
  17.         $this->hasPremium = $hasPremium;
  18.     }
  19.  
  20.     public function checkPremium()
  21.     {
  22.         return $this->hasPremium;
  23.     }
  24. }
  25.  
  26. // Administrative Account Child Class
  27.  
  28. class Admins extends Accounts {
  29.  
  30.     public function __construct()
  31.     {
  32.         $this->hasPremium = true;
  33.     }
  34. }
  35.  
  36. // Normal User Account Class
  37.  
  38. class Users extends Accounts {
  39.  
  40.    
  41.  
  42. }
  43.  
  44. // Instantiate a new user object and check to see if the user has a premium account or not
  45.  
  46. $user = new Users("Ultra", "[email protected]", true);  
  47.  
  48.  
  49. if ($user->checkPremium() === false)
  50. {
  51.     echo "User does not have premium access";
  52. }
  53. else
  54. {
  55.     echo "User has premium access";
  56. }
Add Comment
Please, Sign In to add comment