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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:21:03+00:00 2026-06-11T18:21:03+00:00

A PHP constant is defined like this: define(‘const_name’,’const_value’); Tried like this: define(‘const_name’, $variable_name); Why?

  • 0

A PHP constant is defined like this:

define('const_name','const_value');

Tried like this:

define('const_name', $variable_name);  

Why? because I’m a beginner and I figured if this works:

define('const_name', 50);  

my version will work also. It doesn’t. Should it work and it doesn’t because I mistyped something, or my attempt is just plain stupid?

Note: Inside my variable is a Google Analytics ID extracted from a mysql DB. Just a string like this UA-XXXXX-Y, nothing more.

  • 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-06-11T18:21:04+00:00Added an answer on June 11, 2026 at 6:21 pm
    $myVariable="what up";
    define('myConstant',"$myVariable");
    echo myConstant;
    

    Really though, why define a variable as a constant? This is not a good habit to get into.

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

Sidebar

Related Questions

I have a file that defines constant variables, like this: define_vars.php <? define(something,value); define(something1,value);
In PHP if I define a constant like this: define('FOO', true); if(FOO) do_something(); The
I just define a root path as a constant like this define(ROOT_PATH, dirname(__FILE__)); so,
OK, I have defined a PHP constant that points to a file on the
I've never seen anything like this. File structure: somefolder/base.php includes/stuff.php includes/constants.php base.php: <?php require(../includes/stuff.php);
This is from the php manual: http://us.php.net/manual/en/language.constants.syntax.php If you use an undefined constant, PHP
I learned of the function set_include_path(). All this time, I defined a constant in
I'm trying to do something like a bitwise enum in PHP according to this
Is there any explanation of this strange behavior of defined constant? I have 1
I`m trying to create a small bootstrap in php. my dirs are like this:

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.