Constant Types-PHP


A Constant is an identifier (call) for a Easy value. As the name indicates, that cost Cannot Exchange for the Duration of the Execution of the script (besides for Magic constants, which are not simply constants). A consistent is case-sensitive with the aid of default. With the aid of conference, Constant identifiers are continually Uppercase.
 A constant call begins with a letter or underscore, observed via any range of letters, numbers, or underscores. When you have described a Constant, it could in no way be modified or undefined.
To outline a constant you need to use outline() function and to retrieve the cost of a regular, you need to really specifying its name. Unlike with variables, you do no longer want to have a Constant with a $. You may additionally use the feature Consistent() to examine a Constant's cost if you want to Achieve the Constant's name dynamically.
Constant () function:
As indicated by means of the call, this characteristic will return the fee of the consistent.
This is useful while you need to retrieve fee of a consistent, however you do now not recognize its call, i.E. It's miles stored in a variable or again via a feature.

Constant() Example

                    define("MAXSIZE", 80);
                     echo MAXSIZE;
                  echo constant("MAXSIZE"); // same thing as the previous line
just  Scalar data (Boolean, integer, float and string) can be include in constants.

Differences between constants and variables:

There's no need to jot down a dollar signal ($) earlier than a constant, where as in Variable one has to put in writing a greenback signal.
Constants can't be described by means of simple project, they may only be described using the outline() feature.
Constants may be described and accessed everywhere with out regard to variable scoping regulations.
Once the Constants have been set, may not be redefined or undefined.
Valid and invalid constant names 

// Valid constant names
define("ONE",     "first thing");
define("TWO2",    "second thing");
define("THREE_3", "third thing");

// Invalid constant names
define("2TWO",    "second thing");
define("__THREE__", "third value");

PHP Magic constants:

PHP(Hypertext Preprocessor) affords a large quantity of predefined constants to any script which it runs.
There are five magical constants that exchange relying on in which they may be used. As an instance, the value of  LINE relies upon on the line that it is used on to your script. These special constants are case-insensitive and are as follows....
some "magical" PHP constants ate given underneath....


The contemporary line quantity of the file.


The total route and filename of the report. If used inner an consist of,the name of the included report is returned. For the reason that personal home page four.0.2, FILE  usually consists of an absolute direction while in older variations it contained relative path below some circumstances.


The function name. (delivered in PHP 4.3.0) As of PHP(Hypertext Preprocessor) five this regular returns the feature call as it changed into declared (case-sensitive). In personal home page 4 its fee is constantly lower-cased.


The elegance Call. (introduced in PHP four.3.Zero) As of PHP (Hypertext Preprocessor) 5 this steady returns the magnificence call because it became declared (case-touchy). In PHP 4 its price is continually lower-cased.


The elegance technique name. (brought in PHP five.Zero.Zero) The technique name is returned as it become declared (case-sensitive).


Post a Comment

Popular posts from this blog

Advance PHP Tutorials

Variable Types For PHP