SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: constants

  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    constants

    Just a quick question to verify. The useful life of a declared constant is until you unset it or until the end of the script, correct?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You cannot unset constants. They exists until removed from the source code.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By removed from the source code, do you mean until the script finishes execution? They don't act like session variables, correct? So if I issue a "header('Location: ..." I lose access to it?

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    A constant never changes the constant is always there. If the script that has the constant no longer exists or is not running then the constant cannot be accessed. But no they are not session variables not that it would matter. Constants are readonly values set in the source code for shortcuts.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I appreciate the input. I think I got it.

    Just out of curiousity, from a best practices standpoint, why or when would you use a constant as opposed a regular variable. In effect, a constant is just a variable that you are not going to change, correct? I understand it is a cleaner coding standard and better case of typing, any other advantages?

    Thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •