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

  • Home
  • SEARCH
  • 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 6904043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:00:02+00:00 2026-05-27T08:00:02+00:00

I am building a class that turns a flatfile into a virtual database, I

  • 0

I am building a class that turns a flatfile into a virtual database, I am trying to take the values of an array as the column names instead of indexes when retrieving data like so…

$db = new Database($config, array('first', 'second', 'third', 'fourth'), true);

The array is sent to the constructor in database.php:

public function __construct(Config $config, array $constants = null, $caseInsensitive = false)  {
            $this->_config = $config;
            if(!is_null($constants))
                $this->defineColumns($constants, $caseInsensitive);
            return true;
        } 

Which is passed on to defineColumns():

private function defineColumns($constants, $caseInsensitive) {
            for ($i=0;$i<count($constants);$i++)
                define($constants[$i], $i, $caseInsensitive);   
        }

This works and I can now use first to access column 0, second to access column 1 and so on…

However the define() function seems to make the constants global and accessible from outside the class instance.

I want each set of declared constants to be scoped to the instance alone allowing me to use the same constant again in another instance of the class to access a different column.

Does anyone know a way of doing 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-05-27T08:00:03+00:00Added an answer on May 27, 2026 at 8:00 am

    I’m afraid is not possible if you want to use constants. Constants are global.

    By not using constants, you can store that names in a class static member and use them with something like $myinstance->get('third').

    protected static $columns = array();
    
    private function defineColumns($constants) {
        for ($i=0;$i<count($constants);$i++)
            self::$columns[$constants[$i]] = $i;    
    }
    
    public function get($column) {
        return $IDONTKNOWYOURIMPLEMENTATION[ self::$columns[$column] ];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using prototype 1.7 and building a class that will essentially take a list
I'm building a class that automatically loads a DB record, looks at each DB
I am building a class that handles NSURLConnection requests. To allow other classes to
I'm building a class library that will have some public & private methods. I
To clarify: I'm building a Logger class that allows me to easily log messages:
Say I'm building an ASP.Net class that inherits from IHttpHandler , should I wire
Using c# 4.0 -- building an interface and a class that implements the interface.
I'm building a generic Repository<T> class that supports Linq to SQL, and I'd like
I am building an FTP utility class in C#. In the case that a
I'm currently building a class in PHP that generates PDF documents using the WKHTMLTOPDF

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.