473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"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
Jul 17 '05 #1
2 6353
Joshua Beall wrote:
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.

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";
}
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;


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

Jul 17 '05 #2

"Joshua Beall" <jb****@donotspam.remove.me.heraldic.us> schrieb im
Newsbeitrag news:Bt2Xc.461$Cc.309@trnddc07...
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?


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.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hoox2 | last post by:
void push_front(Node const*& head, int data); Can someone tell me what it means for "const*&"? A reference or a pointer?
5
by: Jim West | last post by:
Could someone please explain to me why the code segment class FOO { public: double *begin(); }; void bar(const FOO &foo) { foo.begin(); }
9
by: July | last post by:
Hello! consider the following code: class A { public: virtual void f() const{ cout << "A::f()" << endl; } };
4
by: C. J. Clegg | last post by:
A month or so ago I read a discussion about putting const ints in header files, and how one shouldn't put things in header files that allocate memory, etc. because they will generate multiple...
3
by: coala | last post by:
In Smart Pointer class, we have a piece of code: inline void release(void) const { if (mPtr) mPtr->release(); mPtr = 0; } It can set mPtr but it is still const? Why could this work and why...
1
by: coala | last post by:
In Smart Pointer class, we have a piece of code: inline void release(void) const { if (mPtr) mPtr->release(); mPtr = 0; } It can set mPtr but it is still const? Why could this work and why...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
4
by: adam.timberlake | last post by:
Me again! I am trying to create a currency converter function for my eCommerce that still pet treats. I am a little short on money recently and so cannot afford a programmer. Can somebody tell me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.