dadamssg Posted June 24, 2012 Share Posted June 24, 2012 so i've been developing in the CodeIgniter framework and i have yet to code an object. My app deals with bookings. So in the database i have columns like: start, end, created, created_by, title, description, etc. I pull the data out and put it into an array. I use my controller functions to validate data and model functions to delete/edit/create the bookings. Should i write a class that creates a Booking object? i don't see how that would benefit me though. How do you guys determine what needs to be an object? Quote Link to comment https://forums.phpfreaks.com/topic/264706-how-do-you-decide-what-needs-to-be-an-object/ Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 From what I understand, the differences aren't vast. There are some links I've clicked through while researching this myself and found some results that show associated arrays are a bit faster ( http://stackoverflow.com/questions/8498114/should-i-use-an-associative-array-or-an-object ). The difference in building them is miniscule anyway. In CI your models are class extensions, so they are inherently prepared for object building and the active record is set up for object construction unless you request it in array format. $this->result() versus $this->result_array() The way I go about it is to create everything as an object and reference it to $this->data to pass to the view. Quote Link to comment https://forums.phpfreaks.com/topic/264706-how-do-you-decide-what-needs-to-be-an-object/#findComment-1356713 Share on other sites More sharing options...
scootstah Posted June 25, 2012 Share Posted June 25, 2012 I always use arrays when using data from a database. A lot of the array functions don't work on objects, so if you want to use them you'll have to at some point convert the object to an array - which is just a waste of time when you could have used arrays to start with. Quote Link to comment https://forums.phpfreaks.com/topic/264706-how-do-you-decide-what-needs-to-be-an-object/#findComment-1356811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.