1 | <?php |
||
17 | class Entity |
||
18 | { |
||
19 | private $db; |
||
20 | |||
21 | /** |
||
22 | * Instantiates a Database object |
||
23 | */ |
||
24 | public function __construct() |
||
28 | |||
29 | /** |
||
30 | * Adds a record to the database and returns the last inserted ID |
||
31 | * @return int |
||
32 | */ |
||
33 | public function add() |
||
41 | |||
42 | /** |
||
43 | * Updates an existing record in the database |
||
44 | */ |
||
45 | public function update() |
||
61 | |||
62 | /** |
||
63 | * Deletes a record from the database |
||
64 | * @return int |
||
65 | */ |
||
66 | public function remove() |
||
76 | |||
77 | /** |
||
78 | * Retrieves a record from the database based on its ID |
||
79 | * and returns it in the form of the corresponding object |
||
80 | * @return object |
||
81 | */ |
||
82 | public function find($id) |
||
88 | |||
89 | /** |
||
90 | * Retrieves all records from the corresponding table in the |
||
91 | * database and returns them as an array of objects |
||
92 | * @return array |
||
93 | */ |
||
94 | public function findAll() |
||
100 | } |
||
101 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: