diff options
Diffstat (limited to 'php.html.markdown')
| -rw-r--r-- | php.html.markdown | 48 | 
1 files changed, 42 insertions, 6 deletions
| diff --git a/php.html.markdown b/php.html.markdown index 7b0cf61c..6944390c 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -3,7 +3,6 @@ language: PHP  contributors:      - ["Malcolm Fell", "http://emarref.net/"]      - ["Trismegiste", "https://github.com/Trismegiste"] -    - [ Liam Demafelix , https://liamdemafelix.com/]  filename: learnphp.php  --- @@ -54,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; @@ -117,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' @@ -141,6 +142,9 @@ $associative = ['One' => 1, 'Two' => 2, 'Three' => 3];  echo $associative['One']; // prints 1 +// Add an element to an associative array +$associative['Four'] = 4; +  // List literals implicitly assign integer keys  $array = ['One', 'Two', 'Three'];  echo $array[0]; // => "One" @@ -157,13 +161,14 @@ unset($array[3]);   * Output   */ -echo 'Hello World!'; +echo('Hello World!');  // Prints Hello World! to stdout.  // Stdout is the web page if running in a browser.  print('Hello World!'); // The same as echo -// print is a language construct too, so you can drop the parentheses +// echo and print are language constructs too, so you can drop the parentheses +echo 'Hello World!';  print 'Hello World!';  $paragraph = 'paragraph'; @@ -335,7 +340,7 @@ switch ($x) {  $i = 0;  while ($i < 5) {      echo $i++; -} // Prints "01234" +}; // Prints "01234"  echo "\n"; @@ -765,6 +770,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 | 
