PHP Constants PHP

Constants are similar to variables, but they may be set only once. Some of them are created automatically by PHP; others you will create with the define function discussed. You do not use the dollar-sign operator to get the value of a constant, and aconstant may never be used on the left side of an assignment operator. Constants ignore scope and are therefore visible inside functions without the use of the global statement. Although it is not necessary, it is customary to name constants exclusively with capital letters.

Using a Constant

Using a Constant

PHP creates several constants upon startup. PHP_VERSION contains the version of PHP running the script. TRUE is set to 1. FALSE is set to 0. PHP_OS describes the operating system. E_ERROR, E_WARNING, E_NOTICE, E_PARSE, E_ALL are for use with the error_reporting function. You can also use __FILE__ and __LINE__ to get the name of the executing script and the line number, respectively. The value of pi is stored in the constant M_PI. Some extensions create constants, too.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics