So I have a data class that has a bunch of properties that reflect a Business' information, like address, phone, etc.. I have the constructor setting all the information via $id being passed, which is used to pull data from the DB.
Then I have a method, set($id), that will update those properties with a new set of information gathered from the database.
The code is kinda long, and makes me annoyed cause I have 8 lines of code that just set each property individually. I don't like it.
I feel like a bad coder doing this so I wanna know if theres a way to dynamically loop through each properly to set it rather then set each separately.
Quickie mock up:
I have no idea if that works. I thought I seen an example like that a little while ago, but I can't find it again. So. I wanna know how to do something like this.
Then I have a method, set($id), that will update those properties with a new set of information gathered from the database.
The code is kinda long, and makes me annoyed cause I have 8 lines of code that just set each property individually. I don't like it.
I feel like a bad coder doing this so I wanna know if theres a way to dynamically loop through each properly to set it rather then set each separately.
Quickie mock up:
Code:
foreach ($dbdata as $k => $v) {
$this->{$k} = $v; }
Comment