From 4d0576490a78b290527919775eb1b5f96f05607a Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 14:34:54 -0700 Subject: Massive edit on PHP --- php.html.markdown | 576 +++++++++++++++++++++++++++--------------------------- 1 file changed, 284 insertions(+), 292 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 339499eb..1a8dea2c 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -6,15 +6,8 @@ author_url: http://emarref.net/ This document describes PHP 5+. -## [Basic Syntax](http://www.php.net/manual/en/language.basic-syntax.php) - -All statements must end with a semi-colon; All PHP code must be between tags. PHP can also be -configured to respect the [short open tags](http://www.php.net/manual/en/ini.core.php#ini.short-open-tag) . - -## [Comments](http://www.php.net/manual/en/language.basic-syntax.comments.php) - ```php - tags // Two forward slashes start a one-line comment. @@ -24,27 +17,36 @@ configured to respect the [short open tags](http://www.php.net/manual/en/ini.cor Surrounding text in slash-asterisk and asterisk-slash makes it a multi-line comment. */ -``` - -## [Types](http://www.php.net/manual/en/language.types.php) -Types are [weakly typed](http://en.wikipedia.org/wiki/Strong_and_weak_typing) and begin with the $ symbol. -A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. +// Use "echo" or "print" to print output +print('Hello '); // Prints "Hello " with no line break -### Scalars +// () are optional for print and echo +echo 'World\n'; // Prints "World" with a line break +// (all statements must end with a semicolon) -```php +// Anything outside Hello World Again! 19 +$int2 = -19; // => -19 +$int3 = 019; // => 15 (a leading 0 denotes an octal number) +$int4 = 0x0F; // => 15 (a leading 0x denotes a hex literal) // Floats (aka doubles) $float = 1.234; @@ -52,28 +54,30 @@ $float = 1.2e3; $float = 7E-10; // Arithmetic -$sum = $number + $float; -$difference = $number - $float; -$product = $number * $float; -$quotient = $number / $float; +$sum = 1 + 1; // 2 +$difference = 2 - 1; // 1 +$product = 2 * 2; // 4 +$quotient = 2 / 1; // 2 // Shorthand arithmetic +$number = 0; $number += 1; // Add 1 to $number -$number++; // Add 1 to $number after it is used -++$number; // Add 1 to $number before it is used. -$number /= $float // Divide and assign the quotient to $number +echo $number++; // Prints 1 (increments after evaluation) +echo ++$number; // Prints 3 (increments before evalutation) +$number /= $float; // Divide and assign the quotient to $number // Strings should be enclosed in single quotes; $sgl_quotes = '$String'; // => '$String' // Avoid using double quotes except to embed other variables -$dbl_quotes = "This is a $sgl_quotes." // => 'This is a $String' +$dbl_quotes = "This is a $sgl_quotes."; // => 'This is a $String' -// Escape special characters with backslash +// Special characters are only escaped in double quotes $escaped = "This contains a \t tab character."; +$unescaped = 'This just contains a slash and a t: \t'; // Enclose a variable in curly braces if needed -$money = "I have $${integer} in the bank." +$money = "I have $${number} in the bank."; // Since PHP 5.3, nowdocs can be used for uninterpolated multi-liners $nowdoc = <<<'END' @@ -81,35 +85,40 @@ Multi line string END; +// Heredocs will do string interpolation $heredoc = << 1, "Two" => 2, "Three" => 3]; -$associative["One"]; // Holds the value 1 -``` -## Output +// Works with all PHP versions +$associative = array('One' => 1, 'Two' => 2, 'Three' => 3); -```php - 1, 'Two' => 2, 'Three' => 3]; + +echo $associative['One']; // prints "1" + +// List literals implicitly assign integer keys +$array = ['One', 'Two', 'Three']; +echo $array[0]; // => "One" + + +/******************************** + * Output + */ echo('Hello World!'); // Prints Hello World! to stdout. @@ -121,133 +130,127 @@ print('Hello World!'); // The same as echo echo 'Hello World!'; print 'Hello World!'; // So is print +$paragraph = 'paragraph'; + echo 100; -echo $variable; -echo function_result(); +echo $paragraph; // If short open tags are configured, or your PHP version is // 5.4.0 or greater, you can use the short echo syntax - -``` - -## [Operators](http://www.php.net/manual/en/language.operators.php) - -### Assignment - -```php +?> +

2 +echo $z; // => 2 +$y = 0; +echo $x; // => 2 +echo $z; // => 0 -```php - $b // TRUE if $a is not equal to $b after type juggling. -$a < $b // TRUE if $a is strictly less than $b. -$a > $b // TRUE if $a is strictly greater than $b. -$a <= $b // TRUE if $a is less than or equal to $b. -$a >= $b // TRUE if $a is greater than or equal to $b. +/******************************** + * Logic + */ +$a = 0; +$b = '0'; +$c = '1'; +$d = '1'; -// The following will only be true if the values match and are the same type. -$a === $b // TRUE if $a is equal to $b, and they are of the same type. -$a !== $b // TRUE if $a is not equal to $b, or they are not of the same type. -1 == '1' // TRUE -1 === '1' // FALSE -``` +// assert throws a warning if its argument is not true -## [Type Juggling](http://www.php.net/manual/en/language.types.type-juggling.php) +// These comparisons will always be true, even if the types aren't the same. +assert($a == $b); // equality +assert($b != $a); // inequality +assert($a <> $b); // alternative inequality +assert($a < $c); +assert($c > $b); +assert($a <= $b); +assert($c >= $d); -Variables can be converted between types, depending on their usage. +// The following will only be true if the values match and are the same type. +assert($c === $d); +assert($a !== $d); +assert(1 == '1'); +assert(1 !== '1'); -```php - 2 $string = '1'; -echo $string + $string; -// Also outputs 2 because the + operator converts the strings to integers +echo $string + $string; // => 2 (strings are coerced to integers) $string = 'one'; -echo $string + $string; +echo $string + $string; // => 0 // Outputs 0 because the + operator cannot cast the string 'one' to a number -``` -Type casting can be used to treat a variable as another type temporarily by using cast operators in parentheses. +// Type casting can be used to treat a variable as another type -```php -$boolean = (boolean) $integer; // $boolean is true +$boolean = (boolean) 1; // => true $zero = 0; -$boolean = (boolean) $zero; // $boolean is false +$boolean = (boolean) $zero; // => false +// There are also dedicated functions for casting most types $integer = 5; $string = strval($integer); -// There are also dedicated functions for casting most types $var = null; // Null value -``` - -## [Control Structures](http://www.php.net/manual/en/language.control-structures.php) -### If Statements -```php - - + This is displayed if the test is truthy. This is displayed otherwise. -``` - -### Switch statements -```php 2, 'car' => 4]; -$wheels = ["bicycle" => 2, "car" => 4]; +// Foreach loops can iterate over arrays +foreach ($wheels as $wheel_count){ + echo "$wheel_count"; +} // Prints "24" +echo "\n"; + +// You can iterate over the keys as well as the values foreach ($wheels as $vehicle => $wheel_count) { echo "A $vehicle has $wheel_count wheels"; } -// This loop will stop after outputting 2 +echo "\n"; + $i = 0; while ($i < 5) { - if ($i == 3) { - break; // Exit out of the while loop and continue. + if ($i === 3) { + break; // Exit out of the while loop } echo $i++; -} +}// Prints "012" -// This loop will output everything except 3 -$i = 0; -while ($i < 5) { - if ($i == 3) { +for($i = 0; $i < 5; $i++){ + if ($i === 3) { continue; // Skip this iteration of the loop } - echo $i++; -} -``` - -## Functions + echo $i; +} // Prints "0124" -Functions are created with the ```function``` keyword. -```php - "Hello" -A valid function name starts with a letter or underscore, followed by any -number of letters, numbers, or underscores. There are three ways to declare functions. +// A valid function name starts with a letter or underscore, followed by any +// number of letters, numbers, or underscores. -### [User-defined](http://www.php.net/manual/en/functions.user-defined.php) - -```php - 5 +echo add(4, 2); // => 6 -// inner_function() does not exist and cannot be called until -// outer_function() is called -``` +// $result is not accessible outside the function +// print $result; // Gives a warning. -This enables [currying](http://en.wikipedia.org/wiki/Currying) in PHP. +// Since PHP 5.3 you can declare anonymous functions; +$inc = function($x){ + return $x + 1; +}; + +echo $inc(2); // => 3 -```php function foo ($x, $y, $z) { echo "$x - $y - $z"; } +// Functions can return functions function bar ($x, $y) { + // Use 'use' to bring in outside variables return function ($z) use ($x, $y) { foo($x, $y, $z); }; @@ -363,92 +358,77 @@ function bar ($x, $y) { $bar = bar('A', 'B'); $bar('C'); -``` - -### [Variable](http://www.php.net/manual/en/functions.variable-functions.php) -```php - 3 +// But, you should probably use anonymous functions instead. -$function_name(); // will execute the my_function_name() function -``` - -### [Anonymous](http://www.php.net/manual/en/functions.anonymous.php) +/******************************** + * Classes + */ -Similar to variable functions, functions may be anonymous. - -```php -instanceProp = $instanceProp; + } + // Methods are declared as functions inside a class + public function myMethod() { + print "MyClass"; } final function youCannotOverrideMe() { } public static function myStaticMethod() { + print "I am static"; } } -$cls = new MyClass(); // The parentheses are optional. +echo MyClass::MY_CONST; // Outputs "value"; +echo MyClass::$staticVar; // Outputs 'static'; +MyClass::myStaticMethod(); // Outputs "I am static"; -echo MyClass::$staticVar; // Access to static vars +// Access class members using ->. +$my_class = new MyClass("An instance property"); // The parentheses are optional. +echo $my_class->property; // => "public" +echo $my_class->instanceProp; // => "An instance property" +$my_class->myMethod(); // => "MyClass" -echo $cls->property; // Access to properties -MyClass::myStaticMethod(); // myStaticMethod cannot be run on $cls -``` +// Extend classes using "extends" +class MyOtherClass extends MyClass{ + function printProtectedProperty(){ + echo $this->protprop; + } -PHP offers some [magic methods](http://www.php.net/manual/en/language.oop5.magic.php) for classes. + // Override a method + function myMethod() { + parent::myMethod(); + print " > MyOtherClass"; + } +} -```php -printProtectedProperty(); // => Prints "protected" +$my_other_class->myMethod(); // Prints "MyClass > MyOtherClass" -class MyClass { +final class YouCannotExtendMe { +} + +// You can use "magic methods" to create getters and setters +class MyMapClass { private $property; public function __get($key) @@ -462,16 +442,13 @@ class MyClass { } } -$x = new MyClass(); +$x = new MyMapClass(); echo $x->property; // Will use the __get() method $x->property = 'Something'; // Will use the __set() method -``` - -Classes can be abstract (using the ```abstract``` keyword), extend other classes (using the ```extends``` keyword) and -implement interfaces (using the ```implements``` keyword). An interface is declared with the ```interface``` keyword. -```php -myTraitMethod(); // Prints "I have MyTrait" + + +/******************************** + * Namespaces + */ + +// 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 myTraitMethod(); ``` ## More Information -- cgit v1.2.3 From 83aeecb68a20751d09bb83793691f19a8dc97aa2 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 20:19:14 -0700 Subject: Added filename parameter --- php.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 1a8dea2c..b3c8f822 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -2,6 +2,7 @@ language: php author: Malcolm Fell author_url: http://emarref.net/ +filename: learnphp.php --- This document describes PHP 5+. -- cgit v1.2.3 From 6f08caf97867f20ac7f2f2dd1eb6b9f63835c80e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 20:25:21 -0700 Subject: Merged PHP review from emarref --- php.html.markdown | 170 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 72 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index b3c8f822..7db50136 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -10,6 +10,8 @@ This document describes PHP 5+. ```php tags +// If your php file only contains PHP code, it is best practise to omit the php closing tag. + // Two forward slashes start a one-line comment. # So will a hash (aka pound symbol) but // is more common @@ -23,7 +25,7 @@ This document describes PHP 5+. print('Hello '); // Prints "Hello " with no line break // () are optional for print and echo -echo 'World\n'; // Prints "World" with a line break +echo "World\n"; // Prints "World" with a line break // (all statements must end with a semicolon) // Anything outside 19 -$int2 = -19; // => -19 -$int3 = 019; // => 15 (a leading 0 denotes an octal number) +$int1 = 19; // => 19 +$int2 = -19; // => -19 +$int3 = 019; // => 15 (a leading 0 denotes an octal number) $int4 = 0x0F; // => 15 (a leading 0x denotes a hex literal) // Floats (aka doubles) @@ -55,26 +57,26 @@ $float = 1.2e3; $float = 7E-10; // Arithmetic -$sum = 1 + 1; // 2 +$sum = 1 + 1; // 2 $difference = 2 - 1; // 1 -$product = 2 * 2; // 4 -$quotient = 2 / 1; // 2 +$product = 2 * 2; // 4 +$quotient = 2 / 1; // 2 // Shorthand arithmetic $number = 0; -$number += 1; // Add 1 to $number -echo $number++; // Prints 1 (increments after evaluation) -echo ++$number; // Prints 3 (increments before evalutation) +$number += 1; // Increment $number by 1 +echo $number++; // Prints 1 (increments after evaluation) +echo ++$number; // Prints 3 (increments before evalutation) $number /= $float; // Divide and assign the quotient to $number // Strings should be enclosed in single quotes; $sgl_quotes = '$String'; // => '$String' // Avoid using double quotes except to embed other variables -$dbl_quotes = "This is a $sgl_quotes."; // => 'This is a $String' +$dbl_quotes = "This is a $sgl_quotes."; // => 'This is a $String.' // Special characters are only escaped in double quotes -$escaped = "This contains a \t tab character."; +$escaped = "This contains a \t tab character."; $unescaped = 'This just contains a slash and a t: \t'; // Enclose a variable in curly braces if needed @@ -110,7 +112,7 @@ $associative = array('One' => 1, 'Two' => 2, 'Three' => 3); // PHP 5.4 introduced a new syntax $associative = ['One' => 1, 'Two' => 2, 'Three' => 3]; -echo $associative['One']; // prints "1" +echo $associative['One']; // prints 1 // List literals implicitly assign integer keys $array = ['One', 'Two', 'Three']; @@ -133,8 +135,8 @@ print 'Hello World!'; // So is print $paragraph = 'paragraph'; -echo 100; -echo $paragraph; +echo 100; // Echo scalar variables directly +echo $paragraph; // or variables // If short open tags are configured, or your PHP version is // 5.4.0 or greater, you can use the short echo syntax @@ -144,10 +146,11 @@ echo $paragraph; $x = 1; $y = 2; -$x = $y; // A now contains the same value sa $y +$x = $y; // $x now contains the same value as $y $z = &$y; -// $x now contains a reference to $y. Changing the value of -// $x will change the value of $y also, and vice-versa. +// $z now contains a reference to $y. Changing the value of +// $z will change the value of $y also, and vice-versa. +// $x will remain unchanged as the original value of $y echo $x; // => 2 echo $z; // => 2 @@ -216,7 +219,7 @@ if (true) { } if (false) { - print "I don't"; + print 'I don\'t'; } else { print 'I get printed'; } @@ -251,7 +254,7 @@ This is displayed otherwise. switch ($x) { case '0': print 'Switch does type coercion'; - break; // You must include a break, or you will fall through + break; // You must include a break, or you will fall through to cases 'two' and 'three' case 'two': case 'three': // Do something if $variable is either 'two' or 'three' @@ -276,16 +279,16 @@ do { echo "\n"; for ($x = 0; $x < 10; $x++) { - echo $x; // Will echo 0 - 9 -}// Prints "0123456789" + echo $x; +} // Prints "0123456789" echo "\n"; $wheels = ['bicycle' => 2, 'car' => 4]; // Foreach loops can iterate over arrays -foreach ($wheels as $wheel_count){ - echo "$wheel_count"; +foreach ($wheels as $wheel_count) { + echo $wheel_count; } // Prints "24" echo "\n"; @@ -303,9 +306,9 @@ while ($i < 5) { break; // Exit out of the while loop } echo $i++; -}// Prints "012" +} // Prints "012" -for($i = 0; $i < 5; $i++){ +for ($i = 0; $i < 5; $i++) { if ($i === 3) { continue; // Skip this iteration of the loop } @@ -318,7 +321,7 @@ for($i = 0; $i < 5; $i++){ */ // Define a function with "function": -function my_function() { +function my_function () { return 'Hello'; } @@ -327,7 +330,7 @@ echo my_function(); // => "Hello" // A valid function name starts with a letter or underscore, followed by any // number of letters, numbers, or underscores. -function add($x, $y = 1) { // $y is optional, and defaults to 2 +function add ($x, $y = 1) { // $y is optional and defaults to 1 $result = $x + $y; return $result; } @@ -339,7 +342,7 @@ echo add(4, 2); // => 6 // print $result; // Gives a warning. // Since PHP 5.3 you can declare anonymous functions; -$inc = function($x){ +$inc = function ($x) { return $x + 1; }; @@ -358,78 +361,92 @@ function bar ($x, $y) { } $bar = bar('A', 'B'); -$bar('C'); +$bar('C'); // Prints "A - B - C" // You can call named functions using strings $function_name = 'add'; echo $function_name(1, 2); // => 3 -// But, you should probably use anonymous functions instead. +// Useful for programatically determining which function to run. +// Alternatively, use call_user_func(callable $callback [, mixed $parameter [, mixed $... ]]); /******************************** * Classes */ -//Classes are defined with the class keyword +// Classes are defined with the class keyword + +class MyClass +{ + const MY_CONST = 'value'; // A constant + + static $staticVar = 'static'; -class MyClass { - const MY_CONST = 'value'; // A constant - static $staticVar = 'static'; - public $property = 'public'; // Properties must declare their visibility - private $privprop = 'private'; // Accessible within the class only - protected $protprop = 'protected'; // Accessible within the class and subclasses + // Properties must declare their visibility + public $property = 'public'; public $instanceProp; + protected $protProp = 'protected'; // Accessible within the class and subclasses + private $privProp = 'private'; // Accessible within the class only // Create a constructor with __construct - public function __construct($instanceProp){ + public function __construct($instanceProp) { // Access instance variables with $this $this->instanceProp = $instanceProp; } + // Methods are declared as functions inside a class - public function myMethod() { - print "MyClass"; + public function myMethod() + { + print 'MyClass'; } - final function youCannotOverrideMe() { + final function youCannotOverrideMe() + { } - public static function myStaticMethod() { - print "I am static"; + public static function myStaticMethod() + { + print 'I am static'; } } -echo MyClass::MY_CONST; // Outputs "value"; -echo MyClass::$staticVar; // Outputs 'static'; -MyClass::myStaticMethod(); // Outputs "I am static"; +echo MyClass::MY_CONST; // Outputs 'value'; +echo MyClass::$staticVar; // Outputs 'static'; +MyClass::myStaticMethod(); // Outputs 'I am static'; -// Access class members using ->. -$my_class = new MyClass("An instance property"); // The parentheses are optional. -echo $my_class->property; // => "public" +// Access class members using -> +$my_class = new MyClass('An instance property'); // The parentheses are optional if not passing in an argument. +echo $my_class->property; // => "public" echo $my_class->instanceProp; // => "An instance property" -$my_class->myMethod(); // => "MyClass" +$my_class->myMethod(); // => "MyClass" // Extend classes using "extends" -class MyOtherClass extends MyClass{ - function printProtectedProperty(){ - echo $this->protprop; +class MyOtherClass extends MyClass +{ + function printProtectedProperty() + { + echo $this->protProp; } // Override a method - function myMethod() { + function myMethod() + { parent::myMethod(); - print " > MyOtherClass"; + print ' > MyOtherClass'; } } -$my_other_class = new MyOtherClass("Instance prop"); +$my_other_class = new MyOtherClass('Instance prop'); $my_other_class->printProtectedProperty(); // => Prints "protected" -$my_other_class->myMethod(); // Prints "MyClass > MyOtherClass" +$my_other_class->myMethod(); // Prints "MyClass > MyOtherClass" -final class YouCannotExtendMe { +final class YouCannotExtendMe +{ } // You can use "magic methods" to create getters and setters -class MyMapClass { +class MyMapClass +{ private $property; public function __get($key) @@ -463,16 +480,19 @@ interface InterfaceTwo abstract class MyAbstractClass implements InterfaceOne { - public $x = "doSomething"; + public $x = 'doSomething'; } class MyConcreteClass extends MyAbstractClass implements InterfaceTwo { - public function doSomething(){ + public function doSomething() + { echo $x; } - public function doSomethingElse(){ - echo "doSomethingElse"; + + public function doSomethingElse() + { + echo 'doSomethingElse'; } } @@ -480,11 +500,14 @@ class MyConcreteClass extends MyAbstractClass implements InterfaceTwo // Classes can implement more than one interface class SomeOtherClass implements InterfaceOne, InterfaceTwo { - public function doSomething(){ - echo "doSomething"; + public function doSomething() + { + echo 'doSomething'; } - public function doSomethingElse(){ - echo "doSomethingElse"; + + public function doSomethingElse() + { + echo 'doSomethingElse'; } } @@ -493,12 +516,13 @@ class SomeOtherClass implements InterfaceOne, InterfaceTwo * Traits */ -//Traits are available since PHP 5.4.0 and are declared using the trait keyword. +// Traits are available since PHP 5.4.0 and are declared using the trait keyword. -trait MyTrait { +trait MyTrait +{ public function myTraitMethod() { - print "I have MyTrait"; + print 'I have MyTrait'; } } @@ -566,3 +590,5 @@ Visit the [official PHP documentation](http://www.php.net/manual/) for reference If you're interested in up-to-date best practices, visit [PHP The Right Way](http://www.phptherightway.com/). If you're coming from a language with good package management, check out [Composer](http://getcomposer.org/). + +For common standards, visit the PHP Framework Interoperability Group's [PSR standards](https://github.com/php-fig/fig-standards). -- cgit v1.2.3 From 789cc2c2a7f77585792bd32ac5e06737891609b1 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 20:38:22 -0700 Subject: Merged in (and formatted line lenghts for) emarref's require commit --- php.html.markdown | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 7db50136..20923548 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -10,7 +10,8 @@ This document describes PHP 5+. ```php tags -// If your php file only contains PHP code, it is best practise to omit the php closing tag. +// If your php file only contains PHP code, it is best practise +// to omit the php closing tag. // Two forward slashes start a one-line comment. @@ -171,8 +172,8 @@ $d = '1'; // These comparisons will always be true, even if the types aren't the same. assert($a == $b); // equality -assert($b != $a); // inequality -assert($a <> $b); // alternative inequality +assert($c != $a); // inequality +assert($c <> $a); // alternative inequality assert($a < $c); assert($c > $b); assert($a <= $b); @@ -254,7 +255,8 @@ This is displayed otherwise. switch ($x) { case '0': print 'Switch does type coercion'; - break; // You must include a break, or you will fall through to cases 'two' and 'three' + break; // You must include a break, or you will fall through + // to cases 'two' and 'three' case 'two': case 'three': // Do something if $variable is either 'two' or 'three' @@ -367,7 +369,45 @@ $bar('C'); // Prints "A - B - C" $function_name = 'add'; echo $function_name(1, 2); // => 3 // Useful for programatically determining which function to run. -// Alternatively, use call_user_func(callable $callback [, mixed $parameter [, mixed $... ]]); +// Or, use call_user_func(callable $callback [, $parameter [, ... ]]); + +/******************************** + * Includes + */ + +/* +``` +```php + -$my_class = new MyClass('An instance property'); // The parentheses are optional if not passing in an argument. echo $my_class->property; // => "public" echo $my_class->instanceProp; // => "An instance property" $my_class->myMethod(); // => "MyClass" @@ -425,7 +468,7 @@ class MyOtherClass extends MyClass { function printProtectedProperty() { - echo $this->protProp; + echo $this->prot; } // Override a method @@ -516,7 +559,7 @@ class SomeOtherClass implements InterfaceOne, InterfaceTwo * Traits */ -// Traits are available since PHP 5.4.0 and are declared using the trait keyword. +// Traits are available from PHP 5.4.0 and are declared using "trait" trait MyTrait { -- cgit v1.2.3 From c3df7c1c5358e34673264122f16ceaf5f17e236c Mon Sep 17 00:00:00 2001 From: Malcolm Fell Date: Sun, 30 Jun 2013 15:52:45 +1200 Subject: Clarify includes and open tags. If it's not PHP, it doesn't need the open tag. --- php.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 20923548..75bbd214 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -379,7 +379,7 @@ echo $function_name(1, 2); // => 3 ``` ```php