SHARE
TWEET

Untitled

a guest Mar 16th, 2018 534 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', "1");
  5.  
  6. abstract class Struct {
  7.   private $_VALUES = array();
  8.   protected $data = array();
  9.  
  10.   public function __set($nam, $val) {
  11.     if (!in_array($nam, $this->_VALUES))
  12.       return null;
  13.  
  14.     $this->data[$nam] = $val;
  15.   }
  16.  
  17.   public function __get($nam) {
  18.     return $this->data[$nam]
  19.   }
  20. }
  21.  
  22. class User extends Struct {
  23.   private $_VALUES = array('login', 'email', 'password')
  24.  
  25.   public function __construct($vals = array()) {
  26.     foreach($vals as $k, $v)
  27.       __set($k, $v);
  28.   }
  29. }
  30.  
  31. $u = new User(array('login' => 'zacheryph'));
  32. $u->email = 'zacheryph@gmail.com';
  33. $u->password = 'kasper';
  34.  
  35. printf("user: %s email: %s\n", $u->login, $u->email);
  36.  
  37. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top