Skip to content

Instantly share code, notes, and snippets.

@alfchee
Created October 2, 2015 03:24
Show Gist options
  • Select an option

  • Save alfchee/6e1dd7df014d9fc2fea2 to your computer and use it in GitHub Desktop.

Select an option

Save alfchee/6e1dd7df014d9fc2fea2 to your computer and use it in GitHub Desktop.
It's an abstract class that works magic methods and properties
<?php
class AbstractModel {
protected $fillable = array();
protected $data = array();
// set magicaly the data attributes
protected function __set($name,$value) {
$this->data[$name] = $value;
}//__set()
protected function __get($name) {
if(array_key_exists($name, $this->data)) {
return $this->data[$name];
}
return null;
}//__get()
protected function __isset($name) {
return isset($this->data['name']);
}
protected function __unset($name) {
unset($this->data[$name]);
}//__unset()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment