-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.php
37 lines (29 loc) · 804 Bytes
/
Model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
class Model
{
// Array to store our key/value attributes
protected $attributes = [];
protected static $table;
// Magic setter to populate $attributes array
public function __set($name, $value)
{
// Set the $name key to hold $value in $attributes
$this->attributes[$name] = $value;
}
// Magic getter to retrieve values from $attributes
public function __get($name)
{
// Check for existence of array key $name
if (array_key_exists($name, $this->attributes)) {
return $this->attributes[$name];
}
return null;
}
public static function getTableName(){
return static::$table;
}
}
$model1 = new Model();
$model1->Name = 'Joe';
$model1->email = '[email protected]';
var_dump($model1);