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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:49:40+00:00 2026-05-25T21:49:40+00:00

If I have a class that will be instantiated that needs to reference data

  • 0

If I have a class that will be instantiated that needs to reference data and/or functions that will be the same for each class. How should this be handled to follow proper programming practices

Example (in PHP):

class Column {
    $_type = null;
    $_validTypes = /* Large array of type choices */;

    public function __construct( $type ) {
        if( type_is_valid( $type ) ) {
             $_type = $type;
        }
    }

    public function type_is_valid( $type ) {
        return in_array( $type, $_validTypes );
    }
}

Then every time a Column is created, it will hold the $_validTypes variable. This variable only really needs to be defined once in memory where all Columns created could refer to a static function type_is_valid for a static class which would hold the $_validTypes variable, declared only once.

Is the idea of a static class, say ColumnHelper or ColumnHandler a good way to handle this? Or is there a way to hold static data and methods within this class? Or is this redefining of $_validTypes for each Column an okay way to do things?

  • 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-05-25T21:49:41+00:00Added an answer on May 25, 2026 at 9:49 pm

    One option would be create a new model for the column configuration e.g.

    class ColumnConfig {
        private $validTypes;
        public isValid($type){
            return isset($this->validType($type))?true:false;
        }
    }
    

    then either add it once to API if you have one, or create one global instance e.g.

    $cc = new ColumnConfig();
    class Column {
        private $cc;
        function __construct($type){
            $this->cc = $this->api->getCC(); // if you have api
            global $cc; // assuming you have no api, an you create a global $cc instance once.
            $this->cc = $cc; // <-- this would pass only reference to $cc not a copy of $cc itself.
    
            if ($this->cc->isValid($type)){
              ....
            }
        }
    }
    

    Sounds like way to go.

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

Sidebar

Related Questions

If you have data for a class that will be modified and needs to
I have written a class that will handle internal logging in my application. Now
I have written an apex class that will create a PDF quote and attach
We have a static method in a utility class that will download a file
So let's assume I have a class named ABC that will have a list
I have a buffer in class 'bufferClass' that will generate a signal to tell
I'm building a class library that will have some public & private methods. I
I have a timeseries class that, over the course of a day will hold
If you have a large class that executes after output(headers/text) is already sent, will
I have some code that will be accessed from two threads: class Timer{ public:

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.