R4R Team working to provide free of cost for experienced and freshers

Tutorials | Examples|Interview Questions and Answers|Java Tutorials| C Tutorials | C++ Tutorials | Spring Tutorials| Hibernate Tutorials | JSP Tutorials | Servelets Tutorials| C# Tutorials | PHP Tutorials etc , Basics | Download Software | Data Types | Variables | Constant | Storage & Classes | Operators | Decisions Making | Loops | Functions| Numbers | Arrays | Pointers | String | Datastructure | Expressions | Preprocessor Statement | I/O | Exception Handling | OOPs Tutorial | Classes and object |C++ Inheritance Overloading | Polymorphism | Abstraction | Encapsulation | Interfaces | Multithreading etc

PHP Programing language

Constants in PHP
Previous Home Next


A constant is an identifier for a simple value. A constant value cannot be modified during the execution of the script. By default a constant is case-sensitive. It can be defined by using define() function or by using keyword const outside a class definition.

echo Student_name;



Valid and Invalid constant names:

//Valid constants name  

//Invalid constants name  
define("2NO_OF_STUDENTS", 60);  
define("__Total__", "total value"); 

PHP Magic constants:

PHP provides a large number of predefined constants to any script which it runs.

SNo. Name Description
1 __LINE__ The current line number of the file.
2 __FILE__ The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.
3 __CLASS__ The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.
4 __TRAIT__ The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar).
5 __METHOD__ The class method name.
6 __FUNCTION__ The function name.
7 __NAMESPACE__ The name of the current namespace.
8 __DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory.
Previous Home Next