Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

defining constant in php

Status
Not open for further replies.

wolf73

Programmer
Feb 12, 2006
93
CA
Hi, I see the following statement in php manual

Constants may only be defined using the define() function, not by simple assignment;

But I try the following code it works
<?php
$test= "abcd";
echo "$test";
?>
 
Wolf,

In your example, $test is a variable, not a constant.

Constants are defined as such:
Code:
define('TEST', "abcd");

The names of each describe their use.

Constants are... constant. You can't change them.
Variables are... variable. You can change them at any time.
 
there is also a difference in scope and assignment.

1. you cannot assign a constant to the output of a function.

2. (to my mind most importantly) a constant is in the global scope.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top