"const" keyword in PHP4? What does it do?

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

    "const" keyword in PHP4? What does it do?

    Hi All,

    What does the "const" reserved word in PHP4 do? I know it is a reserved
    word in PHP4, but the only references I can find to it are for PHP5.

    Here's what I want to do:

    Rather than using define(), I'd like to declare a variable as a constant.
    This way, I can use it in strings. Specifically, in heredoc strings -
    constants don't get interpreted in between <<<EOT and EOT;

    Any ideas?

    -Josh


  • Janwillem Borleffs

    #2
    Re: &quot;const&quo t; keyword in PHP4? What does it do?

    Joshua Beall wrote:[color=blue]
    > What does the "const" reserved word in PHP4 do? I know it is a
    > reserved word in PHP4, but the only references I can find to it are
    > for PHP5.
    >[/color]

    It doesn't do anything in PHP 4 except triggering a parse error. It's used
    in PHP 5 for property declarations within classes:

    class Foo {
    const BAR = "bar";
    }
    [color=blue]
    > Here's what I want to do:
    >
    > Rather than using define(), I'd like to declare a variable as a
    > constant. This way, I can use it in strings. Specifically, in
    > heredoc strings - constants don't get interpreted in between <<<EOT
    > and EOT;
    >[/color]

    Constants cannot be used in heredocs notation (not in PHP 4, not in PHP 5).
    If you want use the value of a constant in this context anyway, you should
    store it in a variable first.


    JW



    Comment

    • Gernot Frisch

      #3
      Re: &quot;const&quo t; keyword in PHP4? What does it do?


      "Joshua Beall" <jbeall@donotsp am.remove.me.he raldic.us> schrieb im
      Newsbeitrag news:Bt2Xc.461$ Cc.309@trnddc07 ...[color=blue]
      > Hi All,
      >
      > What does the "const" reserved word in PHP4 do? I know it is a[/color]
      reserved[color=blue]
      > word in PHP4, but the only references I can find to it are for PHP5.
      >
      > Here's what I want to do:
      >
      > Rather than using define(), I'd like to declare a variable as a[/color]
      constant.[color=blue]
      > This way, I can use it in strings. Specifically, in heredoc[/color]
      strings -[color=blue]
      > constants don't get interpreted in between <<<EOT and EOT;
      >
      > Any ideas?[/color]

      I don't know,. but I could think of making a variable 'const', thus
      not allowing to alter it:

      const $myvar=0.002;
      $myvar = 1.0; // should give an error!?

      I don't know.


      Comment

      Working...