daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 220 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Struct {
  4.   private $_VALUES = array();
  5.   protected $data = array();
  6.  
  7.   public function __set($nam, $val) {
  8.     print_r($this->_VALUES);
  9.     print_r($this->data);
  10.     if (in_array($nam, $this->_VALUES))
  11.       $this->data[$nam] = $val;
  12.   }
  13.  
  14.   public function __get($nam) {
  15.     if (array_key_exists($nam, $this->data))
  16.       return $this->data[$nam];
  17.   }
  18. }
  19.  
  20. class User extends Struct {
  21.  
  22.   public function __construct($vals = array()) {
  23.     $_VALUES = array('login', 'email', 'password');
  24.     foreach($vals as $k => $v)
  25.       $this->$k = $v;
  26.   }
  27. }
  28.  
  29. $u = new User(array('login' => 'zacheryph'));
  30. $u->email = 'zacheryph@gmail.com';
  31. $u->password = 'kasper';
  32.  
  33. printf("user: {$u->login} email: {$u->email}\n");
  34.  
  35. /* OUTPUT:
  36.  
  37. Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) user: email:
  38.  
  39. */
  40.  
  41. ?>
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