From 64aa38a1d28d6e3b9f770e97476f0111f180bd3e Mon Sep 17 00:00:00 2001 From: Akshay Kalose Date: Fri, 16 Oct 2015 22:07:08 -0400 Subject: Add More Magic Methods in PHP --- php.html.markdown | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 39ec5aef..78d9d1f2 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -498,10 +498,23 @@ class MyClass print 'MyClass'; } - //final keyword would make a function unoverridable + // final keyword would make a function unoverridable final function youCannotOverrideMe() { } + + // Magic Methods + + // what to do if Object is treated as a String + public function __toString() { + return $property; + } + + // opposite to __construct() + // called when object no longer referenced + public function __destruct() { + print "Destroying" + } /* * Declaring class properties or methods as static makes them accessible without -- cgit v1.2.3 From d9f3b13e278eebb173253c756ffe847b3188f4af Mon Sep 17 00:00:00 2001 From: Akshay Kalose Date: Sun, 18 Oct 2015 17:37:39 -0400 Subject: Fix Grammar and Syntax --- php.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 78d9d1f2..ac0a83b9 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -511,9 +511,9 @@ class MyClass } // opposite to __construct() - // called when object no longer referenced + // called when object is no longer referenced public function __destruct() { - print "Destroying" + print "Destroying"; } /* -- cgit v1.2.3 From 663f6e28f54a106204b9656d7a1ece1e9f225bcf Mon Sep 17 00:00:00 2001 From: Patrick Lee Date: Thu, 18 Feb 2016 15:59:00 -0500 Subject: Update php.html.markdown Added reference to add an element to an associative array. --- php.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index ce178a15..0be8b427 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -146,6 +146,9 @@ echo $associative['One']; // prints 1 $array = ['One', 'Two', 'Three']; echo $array[0]; // => "One" +// Add an element to an associative array +$array['Four'] = 4; + // Add an element to the end of an array $array[] = 'Four'; // or -- cgit v1.2.3 From a5ae0795ba9e947b6b766707a0b93e5032ba8615 Mon Sep 17 00:00:00 2001 From: Patrick Lee Date: Thu, 18 Feb 2016 16:30:21 -0500 Subject: Update php.html.markdown Moved to group with associative arrays. --- php.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 0be8b427..4acdef98 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -142,13 +142,13 @@ $associative = ['One' => 1, 'Two' => 2, 'Three' => 3]; echo $associative['One']; // prints 1 +// Add an element to an associative array +$array['Four'] = 4; + // List literals implicitly assign integer keys $array = ['One', 'Two', 'Three']; echo $array[0]; // => "One" -// Add an element to an associative array -$array['Four'] = 4; - // Add an element to the end of an array $array[] = 'Four'; // or -- cgit v1.2.3 From c50ff1ddc874ace092507982f881510b27a2e173 Mon Sep 17 00:00:00 2001 From: Patrick Lee Date: Thu, 18 Feb 2016 16:38:15 -0500 Subject: Update php.html.markdown Changed var name to $associative --- 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 4acdef98..6944390c 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -143,7 +143,7 @@ $associative = ['One' => 1, 'Two' => 2, 'Three' => 3]; echo $associative['One']; // prints 1 // Add an element to an associative array -$array['Four'] = 4; +$associative['Four'] = 4; // List literals implicitly assign integer keys $array = ['One', 'Two', 'Three']; -- cgit v1.2.3 From 367f1477f956044e5926c58639e64be68ca70494 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 16 Jun 2016 09:04:40 -0400 Subject: Change curly braces statement (#1804) The '$$' before the braces was a bit confusing. I added a couple lines that show that you have options on where the '$' goes when it comes to curly braces in strings. --- php.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 6c2b38c8..24d656fa 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -88,6 +88,8 @@ $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 +$apples = "I have {$number} apples to eat."; +$oranges = "I have ${number} oranges to eat."; $money = "I have $${number} in the bank."; // Since PHP 5.3, nowdocs can be used for uninterpolated multi-liners -- cgit v1.2.3 From 9420a489f9b45bb00dfe8cf7fd2c8e978378abbc Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 26 Oct 2016 21:14:11 +0200 Subject: [php/en] Normalize PHP code style a bit according to PSR-2 (#2518) --- php.html.markdown | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 24d656fa..82d27546 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -283,7 +283,7 @@ if (false) { if (false) { print 'Does not get printed'; -} elseif(true) { +} elseif (true) { print 'Does'; } @@ -305,7 +305,7 @@ echo $b ?? 'b is not set'; // prints 'Does print' $x = 0; if ($x === '0') { print 'Does not print'; -} elseif($x == '1') { +} elseif ($x == '1') { print 'Does not print'; } else { print 'Does print'; @@ -467,7 +467,7 @@ function variable($word, ...$list) { } } -variable("Separate", "Hello", "World") // Separate || Hello | World | +variable("Separate", "Hello", "World") // Separate || Hello | World | /******************************** * Includes @@ -530,7 +530,8 @@ class MyClass private $priv = '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; } @@ -545,17 +546,19 @@ class MyClass final function youCannotOverrideMe() { } - + // Magic Methods - + // what to do if Object is treated as a String - public function __toString() { + public function __toString() + { return $property; } - + // opposite to __construct() // called when object is no longer referenced - public function __destruct() { + public function __destruct() + { print "Destroying"; } @@ -755,11 +758,15 @@ $cls = new SomeOtherNamespace\MyClass(); * */ -class ParentClass { - public static function who() { +class ParentClass +{ + public static function who() + { echo "I'm a " . __CLASS__ . "\n"; } - public static function test() { + + public static function test() + { // self references the class the method is defined within self::who(); // static references the class the method was invoked on @@ -773,8 +780,10 @@ I'm a ParentClass I'm a ParentClass */ -class ChildClass extends ParentClass { - public static function who() { +class ChildClass extends ParentClass +{ + public static function who() + { echo "But I'm " . __CLASS__ . "\n"; } } -- cgit v1.2.3 From ebc70fe2897cd8fddcde60299fb4fd9b0aae5150 Mon Sep 17 00:00:00 2001 From: Chung-Ping Huang Date: Wed, 16 Nov 2016 14:49:32 +0800 Subject: Add a missing semi-colon (#2572) Add a missing semi-colon at Line 470 --- 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 82d27546..c8e73987 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -467,7 +467,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 7c16ec5ae15ca3d29354179b33f290fb439f434c Mon Sep 17 00:00:00 2001 From: Badal Surana Date: Sat, 3 Dec 2016 16:16:23 +0530 Subject: [php/en] Fix typo (#2590) --- 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 c8e73987..ddf38226 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -824,7 +824,7 @@ echo "Current method is " . __METHOD__; 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__; +echo "Current trait is " . __TRAIT__; /********************** * Error Handling -- cgit v1.2.3 From 34b6b504fa30f8c344ac111ea7474e336136f5c4 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Fri, 16 Jun 2017 00:40:47 -0700 Subject: [PHP/en]Fix small typo in PHP English tutorial (#2761) --- 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 ddf38226..f247ba77 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -342,7 +342,7 @@ switch ($x) { $i = 0; while ($i < 5) { echo $i++; -}; // Prints "01234" +} // Prints "01234" echo "\n"; -- cgit v1.2.3