diff options
Diffstat (limited to 'php.html.markdown')
-rw-r--r-- | php.html.markdown | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/php.html.markdown b/php.html.markdown index f0c5c918..ce228870 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -1,14 +1,15 @@ --- language: php -author: Malcolm Fell -author_url: http://emarref.net/ +contributors: + - ["Malcolm Fell", "http://emarref.net/"] + - ["Trismegiste", "https://github.com/Trismegiste"] filename: learnphp.php --- This document describes PHP 5+. ```php -<?php // PHP code must be enclosed with <?php ? > tags +<?php // PHP code must be enclosed with <?php tags // If your php file only contains PHP code, it is best practise // to omit the php closing tag. @@ -30,7 +31,8 @@ echo "World\n"; // Prints "World" with a line break // (all statements must end with a semicolon) // Anything outside <?php tags is echoed automatically -?>Hello World Again! +?> +Hello World Again! <?php @@ -47,9 +49,9 @@ $boolean = true; // or TRUE or True $boolean = false; // or FALSE or False // Integers -$int1 = 19; // => 19 -$int2 = -19; // => -19 -$int3 = 019; // => 15 (a leading 0 denotes an octal number) +$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) // Floats (aka doubles) @@ -100,6 +102,21 @@ echo 'This string ' . 'is concatenated'; /******************************** + * Constants + */ + +// A constant is defined by using define() +// and can never be changed during runtime! + +// a valid constant name starts with a letter or underscore, +// followed by any number of letters, numbers, or underscores. +define("FOO", "something"); + +// access to a constant is possible by direct using the choosen name +echo 'This outputs '.FOO; + + +/******************************** * Arrays */ @@ -380,9 +397,6 @@ echo $function_name(1, 2); // => 3 * Includes */ -/* -``` -```php <?php // PHP within included files must also begin with a PHP open tag. @@ -526,6 +540,12 @@ interface InterfaceTwo public function doSomethingElse(); } +// interfaces can be extended +interface InterfaceThree extends InterfaceTwo +{ + public function doAnotherContract(); +} + abstract class MyAbstractClass implements InterfaceOne { public $x = 'doSomething'; @@ -590,9 +610,6 @@ $cls->myTraitMethod(); // Prints "I have MyTrait" // This section is separate, because a namespace declaration // must be the first statement in a file. Let's pretend that is not the case -/* -``` -```php <?php // By default, classes exist in the global namespace, and can |