Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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