Using multiple functions for returning or one main function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
parka
Forum Commoner
Posts: 52
Joined: Mon Feb 26, 2007 6:48 am

Using multiple functions for returning or one main function

Post by parka »

Let's say I have a User class.

This User class has some variables, namely id, name, date_of_birth, username etc.

Should I just create one separate function to return each attribute?
Or would it be better to create just one main function and return all the User variables as array items?

I'm guessing the first one should be less taxing for the database. But requires a lot more coding.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Using multiple functions for returning or one main function

Post by yacahuma »

I will say the standard is to have setters and getters for each member function.

One reason that comes tom mind is to help prevents bugs

if you do a get('firstname')

you could , by mistake, type get('firsttname') and you will not get the data
Post Reply