PHP class data implementation

Posted by Bakanyaka on Programmers See other posts from Programmers or by Bakanyaka
Published on 2013-11-21T06:19:54Z Indexed on 2014/06/09 21:39 UTC
Read the original article Hit count: 150

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?

  1. 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

  2. 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?

  1. Method that returns just an array of userdata like this:

    Array([0]=>array([id] => 1, [username] => 'John', ...), 
          [1]=>array([id] => 2, [username] => 'Jack', ...), 
          ...)
    
  2. Method that creates a new instance of it's class for each user and returns an array of objects

© Programmers or respective owner

Related posts about php

Related posts about object-oriented