PHP class data implementation
- by Bakanyaka
I'm studying OOP PHP and have watched two tutorials that implement user login\registration system as an example. But implementation varies. Which way will be more correct one to work with data such as this?
Load all data retrieved from database as array into a property called something like _data on class creation and further methods operate with this property
Create separate properties for each field retrieved from database, on class creation load all data fields into respective properties and operate with that properties separately?
Then let's say I want to create a method that returns a list of all users with their data. Which way is better?
Method that returns just an array of userdata like this:
Array([0]=>array([id] => 1, [username] => 'John', ...),
[1]=>array([id] => 2, [username] => 'Jack', ...),
...)
Method that creates a new instance of it's class for each user and returns an array of objects