PHP Constants

Silimiar to C++, PHP use define keyword to declare a constant.

<?PHP
	define("PI",3.1415926);
	define("OOP", "Object Oriented Programming");
?>

Function constant() returns the value of a constant.

<?PHP
	echo PI; //Print 3.1415926
	echo "PI"; //Print PI
	echo constant("PI");  //Print 3.1415926
?>

PHP built in constants list:

Constant
Description
M_PI
pi, ~3.1415926535898
M_E
e, ~2.718281828459
_LINE_
Line number of current file
_FILE_
Full path name of current file
_DIR_
Directory of current file
_FUNCTION_
Name of current function
_CLASS_
Name of current class
_TRAIT_
Name of current trait
_METHOD_
Name of current class method
_NAMESPACE_
Name of current namespace
FALSE, TRUE, NULL
PHP_VERSION
current php version, also PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, PHP_VERSION_ID, PHP_EXTRA_VERSION
PHP_MAXPATHLEN
Maximum length of filenames
PHP_OS
Current operation system
PHP_SAPI
Server API
PHP_EOL
End of Line
PHP_INT_MAX
Largest integer supported, similar PHP_INT_SIZE
DEFAULT_INCLUDE_PATH
Current PHP search path
PEAR_INSTALL_DIR
Install path of pear, similar PEAR_EXTENSION_DIR
PHP_EXTENSION_DIR
PHP extension directory
PHP_BINDIR
Directories where binaries installed, similiar PHP_MANDIR, PHP_LIBDIR, PHP_DATADIR, PHP_SYSCONFDIR, PHP_LOCALSTATEDIR, PHP_CONFIG_FILE_PATH, PHP_CONFIG_FILE_SCAN_DIR
PHP_SHLIB_SUFFIX
Shared library suffix

PHP ERROR constants:
E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_DEPRECATED, E_USER_DEPRECATED, E_ALL, E_STRICT.

Adjust error reporting using the ERROR constants:

<?PHP
	error_reporting(0); //no error reporting
	error_reporting(E_ALL); //report all errors
	error_reporting(E_ALL ^ E_WARNING); //report all errors except E_WARNING
	error_reporting(E_ERROR | E_WARNING); //report E_ERROR and E_WARNING
?>

:: PHP Tutorials Home ::
PHP String Functions
 • concatenation • echo
 • ereg • ereg_replace
 • explode • htmlspecialchars
 • preg_match • preg_replace
 • preg_split • print,sprintf
 • str_replace • strcmp
 • strpos • strrev
 • strrpos • strtr
 • substr • substr_replace
PHP Array Functions
 • array_diff • array_flip
 • array_intersect • array_key_exists
 • array_keys • array_merge
 • array_pop • array_push
 • array_rand • array_search
 • array_splice • array_unshift
 • array_values • asort & arsort
 • count • in_array
 • ksort • shuffle
 • sort
PHP Data Types
 • array • associative array
 • date & time • number
 • class, object • regular expression
 • string • variables
PHP Loop & Conditions
 • continue & break • for loop
 • foreach • if else
 • not equal • while
PHP File System Functions
 • copy • delete, unlink
 • dirname • download url
 • file_exists • is_file
 • mkdir • read file
 • scandir • write file
PHP Popular Topics
 • ajax • clone
 • comments • constants
 • cookie • database
 • defined • die
 • form validation • gd, draw images
 • global variables • header url
 • heredoc • mail
 • pass by reference • print
 • regular expression • sessions
 • threads • xml parse
PHP Math Functions
 • abs • cos
 • exp • floor & ceil
 • fmod • log
 • max & min • pow
 • round • sin
 • sqrt • tan
convert.idontcarewhatyouthink.net © 2021  Terms of Use | Home