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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:10:41+00:00 2026-05-23T09:10:41+00:00

I have two particular cases where I disagree with a coworker, whether constants should

  • 0

I have two particular cases where I disagree with a coworker, whether constants should be used or not.

We use a homemade framework working roughly like Symfony 1.x.

  1. Initial code was, in a routing PHP config file for routing, like this one:

    $router->map('/some_url', array('module' => 'some_module', 'action' => 'some_action'));
    $router->map('/some_other_url', array('module' => 'some_module', 'action' => 'some_action'));
    // etc.
    

    The coworker changed it to:

    $router->map('/some_url', array(MODULE => 'some_module', ACTION => 'some_action'));
    $router->map('/some_other_url', array(MODULE => 'some_module', ACTION => 'some_action'));
    
    // + in constants.php file:
    define('MODULE', 'module');
    define('ACTION', 'action');
    

    IMO this is constant overuse: if the concept of “module” or “action” is ever renamed, it would have to be renamed in the entire code, either written as a string or a constant. Plus, the defined constant names above have no specific meaning, favoring naming collisions/confusions.

  2. Initial code example:

    if (isset($_SESSION['unid']) && isset($_SESSION['login'])) { ... }
    

    Modified by the coworker:

    if (isset($_SESSION[UNID]) && isset($_SESSION[LOGIN])) { ... }
    
    // + in a constants.php file:
    define('UNID', 'unid');
    define('LOGIN', 'login');
    

    In our application, those session vars names unid and login are clearly unlikely to change. Nonetheless, if declaring constants was really a good practice here, I would suggest at least more precise names, for example FIELDNAME_UNID and FIELDNAME_LOGIN…

Is introducing those constants really relevant (that is, naming should just be improved), or (as I guess) completely useless ?

Thanks.

EDIT

After a few months, here are a few (incredible) lines from the constants.php file.
I definitely find this a completely useless mess, similar to this DailyWTF post. Too many constants kills constants.

define('POST', 'POST');
define('GET', 'GET');

define('PROJECT', 'project');
define('APPLICATION', 'application');
define('MODULE', 'module');
define('ACTION', 'action');
define('ID', 'id');
define('SLUG', 'slug');
define('CONTROLLER', 'controller');
define('CONTENT', 'content');
define('AJAX', 'ajax');
define('EXECUTE', 'execute');
define('FORMAT', 'format');
define('BASE_HREF_CONSTANT', 'basehref');
define('UNID', 'unid');
define('USERNAME', 'username');
define('PASSWORD', 'password');
define('TEMPLATE', 'templates');
define('UNSECURE', 'unsecure');
define('MODE', 'mode');
define('MESSAGE', 'message');
define('TEMPORARY_SESSION', 'temporary_session');
define('ERRORMESSAGE', 'errormessage');
define('START_FROM', 'startfrom');
define('COUNT', 'count');

// and so on.
  • 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-23T09:10:42+00:00Added an answer on May 23, 2026 at 9:10 am

    There is a valid argument for using constants like that.

    If you accidentally do something like:

    $router->map('/some_url', array('moduel' => 'some_module', 'action' => 'some_action'));
    

    it will fail in some undefined way (note the misspelled “moduel”).

    If you make a spelling mistake or typo when a constant is involved, PHP emits a Notice, and you catch it right away.

    How often that actually saves you is a matter for debate. Personally, I usually don’t think it’s worth the trouble.

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

Sidebar

Related Questions

I have applied Two different Image Enhancement Algorithm on a particular Image and got
Most of us know that a loop should not have a non-terminating condition. For
I have a particular saved filter that shows me all cases in a specific
I have two Jenkins projects that share a database. They must not be run
Have two folders with approx. 150 java property files. In a shell script, how
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two tables images2 and image_data So the goal is to have 1
I have two classes (MVC view model) which inherits from one abstract base class.
I have two files client.php and server.php. The client file send a HTTP request
I have two columns say Main and Sub . (they can be of same

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.