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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:08:44+00:00 2026-06-05T02:08:44+00:00

Currently, I am creating a script that will parse information out of a certain

  • 0

Currently, I am creating a script that will parse information out of a certain type of report that it is passed to it. There is a part of the script that will pull a students information from the report and save it for later processing.

Is it best the hold it in the form of a class, or in an array variable? I figure there are 3 methods that I could use.

EDIT: Really, the question comes down to does any one way have any sort of performance advantage? Because otherwise, each method is really the same as the last.

As a class with direct access to variables:

class StudentInformation {

    public $studentID;
    public $firstName;
    public $lastName;
    public $middleName;
    public $programYear;
    public $timeGenerated;

    function StudentInformation(){} 
}

As a class with functions:

class StudentInformation {

    private $studentID;
    private $firstName;
    private $lastName;
    private $middleName;
    private $programYear;
    private $timeGenerated;

    function StudentInformation(){}

    public function setStudentID($id)
    {
        $this->studentID = $id;
    }

    public function getStudentID()
    {
        return $this->studentID;
    }

    public function setFirstName($fn)
    {
        $this->firstName = $fn;
    }

    /* etc, etc, etc */
}

Or as an array with strings as keys:

$studentInfo = array();
$studentInfo["idnumber"] = $whatever;
$studentInfo["firstname"] = $whatever;
$studentInfo["lastname"] = $whatever;
/* etc, etc, etc */
  • 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-05T02:08:45+00:00Added an answer on June 5, 2026 at 2:08 am
    1. Trying to optimize the use of an array vs. a simple value object is probably an unnecessary micro-optimization. For the simplest cases, an array is faster because you don’t have the overhead of constructing a new object.

    2. It’s important to remember this: array is NOT the only data structure that exists. If you don’t need the hash capabilities, a simple SplFixedArraydocs will result in lower memory overhead and faster iteration once you get past the initial overhead of object creation. If you’re storing a large amount of data the aforementioned fixed array or one of the other SPL data structures are likely a better option.

    3. Finally: value objects should be immutable, so in your case I would strongly recommend the encapsulation afforded by an object over the ability to assign hash map values willy-nilly. If you want the simplicity of using the array notation, have your class implement ArrayAccessdocs and get the best of both worlds. Some would suggest magic getters and setters with __get and __set. I would not, as magic generally obfuscates your code unnecessarily. If you really really need magic, you might reconsider your design.

    There’s a reason why the OOP paradigm is recognized as the best programming paradigm that we’ve come up with — because it’s the best paradigm we’ve come up with. You should use it. Avoid falling into the trap of many/most PHP devs who use arrays for everything.

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

Sidebar

Related Questions

I am currently looking at creating a script for my site that will count
I am currently creating a batch script that will import products into a particular
I'm currently creating an SSIS job that will pull picture data from a SQL
I am creating a script which need to parse the yaml output that the
Currently I have the following code creating my timer: <script type=text/javascript> var interval; var
I'm currently creating an AD script that can get the AD groups of one
I'm currently creating a small C# program that inserts data from files into a
I'm currently creating a search form which will send a request to the server
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,
The idea: I'm creating a div that will change to position:fixed once the top

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.