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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:00:01+00:00 2026-05-20T23:00:01+00:00

I have a database table which stores a type for a project which stores

  • 0

I have a database table which stores a “type” for a project which stores either a 1, 2 or 3 where:

1 = “Active”
2 = “Inactive”
3 = “Cancelled”

Currently, I store this mapping in an array in my config.php making it a global variable accessible from my whole application. It looks something like:

$project_types = array(1 => "Active", 2 => "Inactive", 3 => "Cancelled");

Now, I have a Project class, which has get_type() and set_type() methods to alter the integer value as expected.
I want to have a get_type_name() method. Can anyone here explain what this method should look like? Currently, I have something that looks like this:

public function get_type_name() {
    global $project_types;
    return $project_types[$this->get_type()];
}

I the array above should somehow lay inside my Project class, but I’m just not sure what route to take.

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-05-20T23:00:02+00:00Added an answer on May 20, 2026 at 11:00 pm

    Globals are bad, and in your case, creates an unnecessary dependency for your Project class.

    The solution (one of many) is quite simple:
    Create a class property that holds the types and do the lookup on it.

    class Project {
    
        /**
         * @param array Holds human translations of project types.
         */
        protected $_types = array(
            1 => 'Active',
            2 => 'Inactive',
            3 => 'Cancelled',
        );
    
        /**
         * Get a human-readable translation of the project's current type.
         *
         * If a translation can't be found, it returns NULL.
         *
         * @return string|null
         */
        public function get_human_type() {
            $type = $this->get_type();
            return isset($this->_types[$type]) ? $this->_types[$type] : NULL;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table called Posts which stores all the information regarding an
I have a table in my database which stores a tree structure. Here are
I have a database with a table which is full of conditions and error
I have a database table (named Topics) which includes these fields : topicId name
I have a string column in a database table which maps to an Enum
I have a database structure that has a Person table which contains fields such
In a SQL server database, I have a table which contains a TEXT field
I have a database (NexusDB (supposedly SQL-92 compliant)) which contains and Item table, a
I have an Access database in which I drop the table and then create
I have many tables in my database which are interrelated. I have a table

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.