Constants

Constants are identifiers for simple values that will not change during script execution like a variable could. When we create a constant we should use all capital letters and underscores separating words to let yourself and others know they are constants. We use the define() function to create constants. Variable scope rules do not apply to constants so they are available anywhere in a script that they are defined in. They may not be unset or redefined. Create and use a constant:
<?php define("AUTHOR_NAME", "Renew Coder", true); // define(constant_name, value, case_sensitive=true);

echo "The author of this document is named " . AUTHOR_NAME . "."; ?>

Magic Constants

Magic constants represent information that can be accessed about the file and script itself. <?php // Returns the current line number in the file
echo __LINE__; // Returns the file's full path

 


echo __FILE__; // Returns the directory of the file

 


echo __DIR__; // Returns the function name that the code is executing in

 


echo __FUNCTION__; // Returns the class name

 


echo __CLASS__; // Returns the trait name

 


echo __TRAIT__; // Returns the class method name

 


echo __METHOD__; // Returns the namespace name

 


echo __NAMESPACE__; ?>

Predefined Constants

The following constants are defined by the PHP core and are available for use in scripts. <?php echo TRUE; // 1
echo FALSE; // empty

 


echo NULL; // empty

 


echo PHP_VERSION; echo PHP_MAJOR_VERSION; echo PHP_MINOR_VERSION;

 

echo PHP_RELEASE_VERSION; echo PHP_VERSION_ID; echo PHP_EXTRA_VERSION;

 

echo PHP_ZTS; echo PHP_DEBUG;

 

echo PHP_MAXPATHLEN;

 

echo PHP_OS;

 

echo PHP_SAPI;

 

echo PHP_EOL;

 

echo PHP_INT_MAX;

 

echo PHP_INT_SIZE;

 

echo DEFAULT_INCLUDE_PATH;

 

echo PEAR_INSTALL_DIR;

 

echo PEAR_EXTENSION_DIR;

 

echo PHP_EXTENSION_DIR;

 

echo PHP_PREFIX;

 

echo PHP_BINDIR;

 

echo PHP_BINARY;

 

echo PHP_MANDIR;

 

echo PHP_LIBDIR;

 

echo PHP_DATADIR;

 

echo PHP_SYSCONFDIR;

 

echo PHP_LOCALSTATEDIR;

 

echo PHP_CONFIG_FILE_PATH;

 

echo PHP_CONFIG_FILE_SCAN_DIR;

 

echo PHP_SHLIB_SUFFIX; echo E_ERROR;

 

echo E_WARNING; echo E_PARSE;

 

echo E_NOTICE;

 

echo E_CORE_ERROR;

 

echo E_CORE_WARNING;

 

echo E_COMPILE_ERROR;

 

echo E_COMPILE_WARNING;

 

echo E_USER_ERROR;

 

echo E_USER_WARNING;

 

echo E_USER_NOTICE;

 

echo E_DEPRECATED;

 

echo E_USER_DEPRECATED;

 

echo E_ALL;

 

echo E_STRICT;

 

echo __COMPILER_HALT_OFFSET__; ?>

renewdev

I Am Developer And Want To Share My Knowledge With The World..:) ;) . I Have Another Social Networking Website (Renewchat) And For Designing Or Developing Of Website Purpose You Can Contact Me On Renew Coder .. :) ;)

Leave a Reply

Your email address will not be published. Required fields are marked *