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 8466907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:29:02+00:00 2026-06-10T15:29:02+00:00

Would it make more sense in the following situation to create a new object

  • 0

Would it make more sense in the following situation to create a new object type instead of using an array:

I have a simple structure with two values: Name & Age

$ages = array(
     array(
       'name' => 'bill',
       'age'  => 22
    ),
    array(
       'name' => 'bob',
       'age'  => 50
    ),
    // etc
);

The problem is that this structure is generated in one class and passed through a controller and then used in another class.

Therefore it feels like those two classes are tied together as one must know the array keys of this structure that is generated in another.

Is there any design pattern that solves this?

  • 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-10T15:29:04+00:00Added an answer on June 10, 2026 at 3:29 pm

    Since it’s a simple structure you can work with it, but in general it’s recommended to work with objects. If you’ll want to add fields in the future, add levels (nested arrays) – maintenance will be easier as you’re program will be more modular and less coupled:

    // I - easier to use
    $bill_age = $ages->get_age('bill'); 
    // function get_age() is implemented in the class which 
    // makes you code easier to maintain and easier to understand
    
    // II - this implementation is dependent on the structure of $ages 
    // if you'll change $ages - you'll have to change all the uses:
    $bill_arr = $ages[0];
    $bill_age = $bill_arr['age'];
    

    Further, if you’ll have calls like II on different places in the code, changing $ages structure will result in changing all these places, while if you implement I – you have only one place in the code to change (the implementation of get_age($name) inside the class).

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

Sidebar

Related Questions

I edited the question so it would make more sense. I have a function
I'm trying to make sense of a situation I have using entity framework on
I have the following extension method, and would like to make it more generic
Would it make sense to switch to HipHop instead of XCache? Is HipHop ready
Based on this , how would you make ignoring parameters more succint? var m
I would like to make log in process more safely. And to achieve it
I would like to make some of my code more monadic and to use
I would like to make tab completion in bash a bit more intelligent. Let's
Would it make sense to perform git rebase while preserving the commit timestamps? I
I have the following situation: 1) 1 X PhotoTableViewController to display a list of

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.