From 65ee6f72dfdf7fc28c3cc2e8a6c567ac14b551f0 Mon Sep 17 00:00:00 2001 From: Khian Calderon Date: Wed, 25 Dec 2024 11:24:25 +0800 Subject: [PATCH] Added PHP Magic Constants --- Magic_Constants.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Magic_Constants.php diff --git a/Magic_Constants.php b/Magic_Constants.php new file mode 100644 index 0000000..b435717 --- /dev/null +++ b/Magic_Constants.php @@ -0,0 +1,35 @@ +"; // Output current line number +echo "Full file path: " . __FILE__ . "
"; // Output the full path to the file +echo "Directory path: " . __DIR__ . "
"; // Output the directory of the file + +// Function example using __FUNCTION__ +function exampleFunction() { + echo "Function name: " . __FUNCTION__ . "
"; // Output current function's name +} +exampleFunction(); + +// Class example using __CLASS__ +class ExampleClass { + function displayClassName() { + echo "Class name: " . __CLASS__ . "
"; // Output current class's name + } +} +$obj = new ExampleClass(); +$obj->displayClassName(); + +// Method example using __METHOD__ +class MethodExample { + public function showMethodName() { + echo "Method name: " . __METHOD__ . "
"; // Output current method's name + } +} +$obj2 = new MethodExample(); +$obj2->showMethodName(); + +// Namespace example using __NAMESPACE__ +echo "Current namespace: " . __NAMESPACE__ . "
"; +?>