Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:40:37+00:00 2026-06-06T04:40:37+00:00

I was wondering which way is better to work with. Using private attributes at

  • 0

I was wondering which way is better to work with.
Using private attributes at a controller class, or using only one private attribute as an array of attributes.

Instead of:

class User{

    private $id;
    private $firstName;
    private $surname;
    private $age;
    private $gender;
    private $city;
    ...
    ...
}


class User{

    private $data;
}

and then be able to do something like this:

function __construct(){
     //this would contain id, firstName, username, age, gender...
    $data = $model->getData();
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:40:39+00:00Added an answer on June 6, 2026 at 4:40 am

    Using arrays you will loose any autocompletion tools while writing code on your class. You will loose the ability to detect syntax errors on your attributes. You will in fact make your code more confuse, less descriptive.

    Using objects is usually a good thing to allow for a better maintainability, for things that will be shared with several developers, or with yourself several months or years after you’ve been writing it. In my opinion you should stay with attributes. A more confuse code may be ‘optimised, or shorter to read, but if you want that just write assembly code. If you want to make object code, do it in a clean way, you will always find a situation where it will save your future life.

    Your problem here is that you maybe think it’s a real pain to maitain a clean mapping between your object attributes and the Model layers columns. But whatever you try, this is the minimum thing you will always have to code in all your application, if it’s not done here you will still have to know these attributes when using your object. Chances are that this is a Pattern of Failure:

    Most of us developers embrace the Don’t Repeat Yourself/Duplication Is Evil principle, and we apply whenever we can to the software we create. But one of the deadliest pitfalls we can make is waving the wand of abstraction too quickly and too broadly, and we often forget that the consequence of unnecessary duplication is far less than the consequence of unnecessary consolidation.

    With your DataModel loading example I can see for example two potential future problems:

    • let’s imagine that in the future you’ll have a binary attributes, and that attribute requires lazy loading, whatever you do you’ll certainly ends with a dirty solution around your __construct.
    • you are now building some instance of your class objects, you need to feed the data of theses objects with some data which do not come from the model (a sort of cache maybe), and you have thousands of theses objects. But everytime you construct such object all attributes are filled from the model.

    In fact if you want to make something filling the object attributes based on the object related model you should really think it a something more general, maybe implying other objects, interfaces, factories, several methods. And at least not in the construct.

    Use array for arrays, and attributes for attributes, let the PHP engine optimize attributes management, I’m sure code optimizer will make better things with attributes than with arrays indexed by strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Websphere portal 6.0 and I'm wondering if there's a way in which
I am wondering which way would end up being faster, selecting elements by: $('element[href=#my_link]');
I was wondering which is the way to make this simple (and maybe stupid)
I was wondering what is the difference between the following and which way is
I am wondering is there any way to execute following shell script, which waits
I'm wondering if a number is represented one way in a floating point representation,
I am wondering which is more efficient, to store temporary data (related to that
I was wondering which kind of expressiveness fits a language used to generate particle
I was wondering which DVCS is most conducive to experimentation i.e. branching, etc. I
I was wondering which tool in ORACLE 11g (their latest DBMS) can be used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.