02 Php Constants 02 Php Constants
PHP Magic Constants
__LINE__
This constant returns the current line number of the file where it was use.
Demo:
This is the line number 15
__FILE__
The __FILE__
constant returns the path and filename of the file where it is being used. Since it returns the full path this makes it useful in debugging and file management.
Demo:
This file is at /var/www/vhosts/tdavis.bitweb1.nwtc.edu/httpdocs/php/research-documentation/02-php-constants/02-php-constants.php
__DIR__
This shows the file directory. Used in an include the directory of the included file will be returned and a trailing slash is only used when in the root directory.
Demo:
Current file is in this directory: /var/www/vhosts/tdavis.bitweb1.nwtc.edu/httpdocs/php/research-documentation/02-php-constants
__FUNCTION__
The constant __FUNCTION__
returns a function name where it is being used. You can include it when handling errors to know exactly where an error occurred.
Demo:
This is my demo function called Rabbit