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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:10:27+00:00 2026-05-10T21:10:27+00:00

This is for my DB class. I am new to OO, been a procedural

  • 0

This is for my DB class. I am new to OO, been a procedural lad for some time, so I’m still a bit murky.

My first idea was using a bunch of setter functions/methods.. but after writing a whole bunch, I thought about using PHP’s define function, like so.

define('MYSQL_USERNAME', 'jimbo'); 

Is this an accepted practice? What is the best practice? Should I really clutter my class with a bunch of setter functions (I am currently the only developer using these classes). What are your solutions?

Thank you!

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

    I use const only for creating mnemonic names for immutable constants in the class. The define() function does not create constants as part of the class, it creates constants in the global space.

    class MyClass {   const CONFIG_FILE = 'myapp.ini'; 

    Class configuration data I usually declare as a protected hash-array in the class. Keys are useful for mnemonics. Values are defaults.

      protected $config = array(     'logfile' => 'err.out',     'debug' => false   ); 

    Then I load an ‘ini’ format file with parse_ini_file() and use array_merge() to map the keys into your class config array:

      public function __construct() {     $ini_data = parse_ini_file(self::CONFIG_FILE, __CLASS__);     $this->config = array_merge($this->config, $ini_data);   }  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many years ago I remember a fellow programmer counselling this: new Some::Class; # bad!
ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is
I am doing something like this: class Class(object): def __init__(self): self.var=#new instance name string#
ASP.NET MVC - what is this in VB.NET? Html.TextBox( name, null, new { @class
I came across this class while reading a C# book and have some questions.
I've been a procedural programmer for over 4 yrs and it's time to start
I haven't been able to find this explicitly stated anywhere yet, but a bunch
I'm new to Delphi, and I've been running some tests to see what object
I'm a Java newbie, and also new to OOP. I have been a procedural
I'm working with a class for which the new operator has been made private,

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.