mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-07-25 17:11:53 +02:00
Merge pull request #1964 from lesaff/patch-1
Add PHP magic constants entry
This commit is contained in:
@@ -767,6 +767,37 @@ I'm a ParentClass
|
|||||||
But I'm ChildClass
|
But I'm ChildClass
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* Magic constants
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Get current class name. Must be used inside a class declaration.
|
||||||
|
echo "Current class name is " . __CLASS__;
|
||||||
|
|
||||||
|
// Get full path directory of a file
|
||||||
|
echo "Current directory is " . __DIR__;
|
||||||
|
|
||||||
|
// Typical usage
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
// Get full path of a file
|
||||||
|
echo "Current file path is " . __FILE__;
|
||||||
|
|
||||||
|
// Get current function name
|
||||||
|
echo "Current function name is " . __FUNCTION__;
|
||||||
|
|
||||||
|
// Get current line number
|
||||||
|
echo "Current line number is " . __LINE__;
|
||||||
|
|
||||||
|
// Get the name of the current method. Only returns a value when used inside a trait or object declaration.
|
||||||
|
echo "Current method is " . __METHOD__;
|
||||||
|
|
||||||
|
// Get the name of the current namespace
|
||||||
|
echo "Current namespace is " . __NAMESPACE__;
|
||||||
|
|
||||||
|
// Get the name of the current trait. Only returns a value when used inside a trait or object declaration.
|
||||||
|
echo "Current namespace is " . __TRAIT__;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* Error Handling
|
* Error Handling
|
||||||
|
Reference in New Issue
Block a user