From 3777d8a0597925ac15fe1405cd723f4a613794ae Mon Sep 17 00:00:00 2001 From: Greg Barendt Date: Thu, 15 Oct 2015 16:28:38 -0400 Subject: Remove an extraneous space --- 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 39ec5aef..f6f965fb 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -702,7 +702,7 @@ $cls = new SomeOtherNamespace\MyClass(); try { // Do something -} catch ( Exception $e) { +} catch (Exception $e) { // Handle exception } -- cgit v1.2.3 From 6c14f507c24524de4815cac05b55bf9a56e7cd06 Mon Sep 17 00:00:00 2001 From: Brett Taylor Date: Fri, 16 Oct 2015 12:04:17 +1300 Subject: Adds late static binding to PHP reference --- php.html.markdown | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 39ec5aef..e64f7bfe 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -693,6 +693,43 @@ use My\Namespace as SomeOtherNamespace; $cls = new SomeOtherNamespace\MyClass(); + +/********************** +* Late Static Binding +* +* / + +class ParentClass { + public static function who() { + echo "I'm a " . __CLASS__ . "\n"; + } + public static function test() { + // self references the class the method is defined within + self::who(); + // static references the class the method was invoked on + static::who(); + } +} + +ParentClass::test(); +/* +I'm a ParentClass +I'm a ParentClass +*/ + +class ChildClass extends ParentClass { + public static function who() { + echo "But I'm " . __CLASS__ . "\n"; + } +} + +ChildClass::test(); +/* +I'm a ParentClass +But I'm ChildClass +*/ + + /********************** * Error Handling * @@ -708,9 +745,9 @@ try { // When using try catch blocks in a namespaced enviroment use the following -try { +try { // Do something -} catch (\Exception $e) { +} catch (\Exception $e) { // Handle exception } @@ -719,13 +756,13 @@ try { class MyException extends Exception {} try { - - $condition = true; - + + $condition = true; + if ($condition) { throw new MyException('Something just happend'); } - + } catch (MyException $e) { // Handle my exception } -- cgit v1.2.3 From ed4ac31d97b36866a48faf3b9328c320ba55074f Mon Sep 17 00:00:00 2001 From: Sawyer Charles Date: Sun, 18 Oct 2015 17:46:23 -0500 Subject: Added variable amount of parameters as of php 5.6+ --- php.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 5bc2ddce..e7b57b4b 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -445,6 +445,16 @@ function parameters() { parameters('Hello', 'World'); // Hello | 0 - Hello | 1 - World | +// Since PHP 5.6 you can get a variable number of arguments +function variable($word, ...$list) { + echo $word . " || "; + foreach ($list as $item) { + echo $item . ' | '; + } +} + +variable("Separate", "Hello", "World") // Separate || Hello | world | + /******************************** * Includes */ -- cgit v1.2.3 From b4c8ff365ee1d633470ced72de5f540744fa921a Mon Sep 17 00:00:00 2001 From: Sawyer Charles Date: Sun, 18 Oct 2015 17:47:42 -0500 Subject: capital letter --- 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 e7b57b4b..71f23871 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -453,7 +453,7 @@ function variable($word, ...$list) { } } -variable("Separate", "Hello", "World") // Separate || Hello | world | +variable("Separate", "Hello", "World") // Separate || Hello | World | /******************************** * Includes -- cgit v1.2.3 From 087dbecb2f25c2d372ed4e007f7641cbc87c0571 Mon Sep 17 00:00:00 2001 From: Tom Duff Date: Sun, 18 Oct 2015 20:21:42 -0400 Subject: Add more examples and explanations Added some clarifying examples to sections on echo(), constants, and cleaned up formatting on others. Added further explanation about the spaceship operator. --- php.html.markdown | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 5bc2ddce..127e601b 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -104,7 +104,8 @@ END; echo 'This string ' . 'is concatenated'; // Strings can be passed in as parameters to echo -echo 'Multiple', 'Parameters', 'Valid'; +echo 'Multiple', 'Parameters', 'Valid'; // Returns 'MultipleParametersValid' + /******************************** * Constants @@ -117,8 +118,10 @@ echo 'Multiple', 'Parameters', 'Valid'; // 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; +// 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' + /******************************** @@ -159,9 +162,9 @@ echo('Hello World!'); print('Hello World!'); // The same as echo -// echo is actually a language construct, 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!'; // So is print +print 'Hello World!'; $paragraph = 'paragraph'; @@ -219,7 +222,11 @@ assert($a !== $d); assert(1 === '1'); assert(1 !== '1'); -// spaceship operator since PHP 7 +// 'Spaceship' operator (since PHP 7) +// Returns 0 if values on either side are equal +// Returns 1 if value on the left is greater +// Returns -1 if the value on the right is greater + $a = 100; $b = 1000; -- cgit v1.2.3 From c69ef3115bb900a5b2f716ebd9791a38ca113ab7 Mon Sep 17 00:00:00 2001 From: labrack Date: Thu, 22 Oct 2015 13:06:15 -0400 Subject: [php/en] Un-beef a comment block closing Somebody beefed a closing on the 'Late Static Binding' Comment block, causing the next 18 or so lines to be included in the comment instead of parsed for syntax properly. --- 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 127e601b..403fc41d 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -723,7 +723,7 @@ $cls = new SomeOtherNamespace\MyClass(); /********************** * Late Static Binding * -* / +*/ class ParentClass { public static function who() { -- cgit v1.2.3