summaryrefslogtreecommitdiffhomepage
path: root/php.html.markdown
diff options
context:
space:
mode:
authorAdam Bard <github@adambard.com>2016-01-06 04:05:23 +0800
committerAdam Bard <github@adambard.com>2016-01-06 04:05:23 +0800
commitd656adc3f2693c6e9fb3973e414ed3dec45d54a6 (patch)
treeb1d11296c40700949c0c332eee1b91801539595f /php.html.markdown
parentb41359b92b5b0a1c69f0c4892bc5c63e46d43f77 (diff)
parentdc1c759c2903f15fd3c52c2241c765c65fbe9d89 (diff)
Merge pull request #1964 from lesaff/patch-1
Add PHP magic constants entry
Diffstat (limited to 'php.html.markdown')
-rw-r--r--php.html.markdown31
1 files changed, 31 insertions, 0 deletions
diff --git a/php.html.markdown b/php.html.markdown
index 02249cd3..ce178a15 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -767,6 +767,37 @@ I'm a ParentClass
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