summaryrefslogtreecommitdiffhomepage
path: root/php.html.markdown
diff options
context:
space:
mode:
authorAdam <adam@adambard.com>2016-01-08 14:35:53 +0800
committerAdam <adam@adambard.com>2016-01-08 14:35:53 +0800
commitef28fa69775ba064dfed212e034b5caae7edb7b9 (patch)
treed3a30be274822754414b438fe9b9c102edc09630 /php.html.markdown
parent8ad537a9ba9889234a63c5a38caeab3e225856e4 (diff)
parent04166190367a93236e7173901dff7ae9661736ba (diff)
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
Diffstat (limited to 'php.html.markdown')
-rw-r--r--php.html.markdown37
1 files changed, 35 insertions, 2 deletions
diff --git a/php.html.markdown b/php.html.markdown
index 0504ced2..ce178a15 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -53,6 +53,8 @@ $int1 = 12; // => 12
$int2 = -12; // => -12
$int3 = 012; // => 10 (a leading 0 denotes an octal number)
$int4 = 0x0F; // => 15 (a leading 0x denotes a hex literal)
+// Binary integer literals are available since PHP 5.4.0.
+$int5 = 0b11111111; // 255 (a leading 0b denotes a binary number)
// Floats (aka doubles)
$float = 1.234;
@@ -116,11 +118,11 @@ echo 'Multiple', 'Parameters', 'Valid'; // Returns 'MultipleParametersValid'
// a valid constant name starts with a letter or underscore,
// followed by any number of letters, numbers, or underscores.
-define("FOO", "something");
+define("FOO", "something");
// access to a constant is possible by calling the choosen name without a $
echo FOO; // Returns 'something'
-echo 'This outputs '.FOO; // Returns 'This ouputs something'
+echo 'This outputs ' . FOO; // Returns 'This ouputs something'
@@ -765,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