Constant or Variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raven

    #1

    Constant or Variable?

    Opinions please. I'd like to hear the pro's and con's of

    define('BASENAM E',dirname($_SE RVER['PHP_SELF']));

    or

    $basename = dirname($_SERVE R['PHP_SELF']);

    I know that one pro is that the constant can't be changed which is my
    ultimate goal, but I solicit your comments.

    --


  • Jan Pieter Kunst

    #2
    Re: Constant or Variable?

    Raven wrote:[color=blue]
    > Opinions please. I'd like to hear the pro's and con's of
    >
    > define('BASENAM E',dirname($_SE RVER['PHP_SELF']));
    >
    > or
    >
    > $basename = dirname($_SERVE R['PHP_SELF']);
    >
    > I know that one pro is that the constant can't be changed which is my
    > ultimate goal, but I solicit your comments.
    >[/color]

    A tiny little 'con' might be that you can do

    "long string $basename long string"

    with a variable, but you must do

    'long string ' . BASENAME . ' long string'

    with the constant.

    But I really don't think that is important.

    A pro is that constants are global: with a variable you must do:

    $basename = dirname($_SERVE R['PHP_SELF']);

    function blah() {
    global $basename;

    ... $basename ...
    }

    but with a constant you do:

    define('BASENAM E',dirname($_SE RVER['PHP_SELF']));

    function blah() {

    ... BASENAME ...
    }

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    Working...