How to get current directory, filename and code line number in PHP
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
To get the current directory
__DIR__: This constant is used to get the current directory of the file. This is equivalent to the dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. If used inside an include method, the directory of the included file is returned.
Output: The current directory of this file is 'C:\wamp\www\demo'.
To get the current filename with full file path
__FILE__: This is used to return the full file path and filename of the file. If used inside an include method, the name of the included file is returned.
Output: The current file with path is 'C:\wamp\www\demo\magic_const.php'.
This magic constant is mostly used in case where we have to include some files from the directory.
To get the current line number
__LINE__: This is used to return the current line number of the file.
Output: The line number of this code is '34'.
need an explanation for this answer? contact us directly to get an explanation for this answerThis constant is mostly used while debugging the code or to get line number of the error.