From a46ae22bf785bf74334a309c9b2f0a64f5a05659 Mon Sep 17 00:00:00 2001 From: paierlep Date: Wed, 3 Jul 2013 19:50:20 +0200 Subject: Update php.html.markdown a few sentences to constants --- php.html.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index f0c5c918..c6811282 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -99,6 +99,21 @@ END; 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 */ -- cgit v1.2.3 From 040896b050e92a44c7c58be51ff4c9b8b7bb523d Mon Sep 17 00:00:00 2001 From: paierlep Date: Wed, 3 Jul 2013 19:55:03 +0200 Subject: Update php.html.markdown ?> instead of ? > --- 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 c6811282..73445839 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -8,7 +8,7 @@ filename: learnphp.php This document describes PHP 5+. ```php - tags + tags // If your php file only contains PHP code, it is best practise // to omit the php closing tag. -- cgit v1.2.3 From 18a5e58b16e6e0b172c010fd3bba07e81701222a Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 2 Aug 2013 09:40:22 -0700 Subject: Fixed php and removed old VB file --- php.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 5f5a4b54..ce228870 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -9,7 +9,7 @@ filename: learnphp.php This document describes PHP 5+. ```php - tags +Hello World Again! +?> +Hello World Again! Date: Mon, 12 Aug 2013 17:34:17 -0700 Subject: Added visibility to static variable declarations --- php.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index ce228870..083574ee 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -440,6 +440,11 @@ class MyClass static $staticVar = 'static'; + // Static variables and their visibility + public static $publicStaticVar = 'publicStatic'; + private static $privateStaticVar = 'privateStatic'; // Accessible within the class only + protected static $protectedStaticVar = 'protectedStatic'; // Accessible from the class and subclasses + // Properties must declare their visibility public $property = 'public'; public $instanceProp; -- cgit v1.2.3 From ef0601bab5c3f7f57e584594fc34da87cf8cce9c Mon Sep 17 00:00:00 2001 From: Afaq Date: Sun, 25 Aug 2013 11:43:07 -0400 Subject: Updated PHP doc to include print_r() and var_dump() --- php.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 083574ee..1a07777a 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -176,6 +176,11 @@ $y = 0; echo $x; // => 2 echo $z; // => 0 +// Dumps type and value of variable to stdout +var_dumb($z); // prints int(3) + +// Prints variable to stdout in human-readable format +print_r($array); // prints: Array ( [0] => One [1] => Two [2] => Three ) /******************************** * Logic -- cgit v1.2.3 From 7af1a853d474fce4feae2429d5e194649fc59105 Mon Sep 17 00:00:00 2001 From: Afaq Date: Sun, 25 Aug 2013 11:49:49 -0400 Subject: Correction to variable output of var_dump() --- 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 1a07777a..1cc6d2c5 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -177,7 +177,7 @@ echo $x; // => 2 echo $z; // => 0 // Dumps type and value of variable to stdout -var_dumb($z); // prints int(3) +var_dumb($z); // prints int(0) // Prints variable to stdout in human-readable format print_r($array); // prints: Array ( [0] => One [1] => Two [2] => Three ) -- cgit v1.2.3 From 92e921e8f3a9138bdb94b19a15cb76081cc90689 Mon Sep 17 00:00:00 2001 From: ipscott Date: Thu, 29 Aug 2013 23:50:11 -0500 Subject: Update php.html.markdown added a better description for static functions and properties --- php.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 1cc6d2c5..aa73c547 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -468,10 +468,16 @@ class MyClass print 'MyClass'; } + //final keyword would make a function unoverridable final function youCannotOverrideMe() { } +/* +Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. +A property declared as static can not be accessed with an instantiated class object (though a static method can). +*/ + public static function myStaticMethod() { print 'I am static'; -- cgit v1.2.3 From 6071e57cd962462e720f33ec7870810cd67ba528 Mon Sep 17 00:00:00 2001 From: afaqurk Date: Sat, 31 Aug 2013 23:29:51 -0400 Subject: spelling error on php function: var_dumb() = var_dump() --- 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 1cc6d2c5..0ff31dd2 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -177,7 +177,7 @@ echo $x; // => 2 echo $z; // => 0 // Dumps type and value of variable to stdout -var_dumb($z); // prints int(0) +var_dump($z); // prints int(0) // Prints variable to stdout in human-readable format print_r($array); // prints: Array ( [0] => One [1] => Two [2] => Three ) -- cgit v1.2.3 From ba17d5b9877f324fa633c1670c49e6a867ba5734 Mon Sep 17 00:00:00 2001 From: afaqurk Date: Sat, 31 Aug 2013 23:44:15 -0400 Subject: Added unset function to arrays and variables. Added the unset function to show the varying effects of deleting/removing variables and elements of an array. --- php.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 0ff31dd2..19f507ad 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -59,6 +59,9 @@ $float = 1.234; $float = 1.2e3; $float = 7E-10; +// Delete variable +unset($int1) + // Arithmetic $sum = 1 + 1; // 2 $difference = 2 - 1; // 1 @@ -136,6 +139,11 @@ echo $associative['One']; // prints 1 $array = ['One', 'Two', 'Three']; echo $array[0]; // => "One" +// Add an element to the end of an array +$array[] = 'Four'; + +// Remove element from array +unset($array[3]); /******************************** * Output -- cgit v1.2.3 From 4f0206f5aa373bf477bf88d62df720656d3aca2e Mon Sep 17 00:00:00 2001 From: Matthew Johnston Date: Sun, 8 Sep 2013 15:31:46 -0500 Subject: Fixed line wrapping --- php.html.markdown | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 0caa07b6..1952d833 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -107,7 +107,7 @@ echo 'This string ' . 'is concatenated'; /******************************** * Constants */ - + // A constant is defined by using define() // and can never be changed during runtime! @@ -143,7 +143,7 @@ echo $array[0]; // => "One" $array[] = 'Four'; // Remove element from array -unset($array[3]); +unset($array[3]); /******************************** * Output @@ -455,8 +455,10 @@ class MyClass // Static variables and their visibility public static $publicStaticVar = 'publicStatic'; - private static $privateStaticVar = 'privateStatic'; // Accessible within the class only - protected static $protectedStaticVar = 'protectedStatic'; // Accessible from the class and subclasses + // Accessible within the class only + private static $privateStaticVar = 'privateStatic'; + // Accessible from the class and subclasses + protected static $protectedStaticVar = 'protectedStatic'; // Properties must declare their visibility public $property = 'public'; @@ -476,14 +478,15 @@ class MyClass print 'MyClass'; } - //final keyword would make a function unoverridable + //final keyword would make a function unoverridable final function youCannotOverrideMe() { } /* -Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. -A property declared as static can not be accessed with an instantiated class object (though a static method can). + * Declaring class properties or methods as static makes them accessible without + * needing an instantiation of the class. A property declared as static can not + * be accessed with an instantiated class object (though a static method can). */ public static function myStaticMethod() @@ -674,10 +677,14 @@ $cls = new SomeOtherNamespace\MyClass(); ## More Information -Visit the [official PHP documentation](http://www.php.net/manual/) for reference and community input. +Visit the [official PHP documentation](http://www.php.net/manual/) for reference +and community input. -If you're interested in up-to-date best practices, visit [PHP The Right Way](http://www.phptherightway.com/). +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/). +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). +For common standards, visit the PHP Framework Interoperability Group's +[PSR standards](https://github.com/php-fig/fig-standards). -- cgit v1.2.3 From a3476993b1d44ea033967f979dfa022f0fd72429 Mon Sep 17 00:00:00 2001 From: Arnel Bucio Date: Sun, 15 Sep 2013 14:15:53 +0800 Subject: Fix typo --- 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 1952d833..226eefff 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -72,7 +72,7 @@ $quotient = 2 / 1; // 2 $number = 0; $number += 1; // Increment $number by 1 echo $number++; // Prints 1 (increments after evaluation) -echo ++$number; // Prints 3 (increments before evalutation) +echo ++$number; // Prints 3 (increments before evaluation) $number /= $float; // Divide and assign the quotient to $number // Strings should be enclosed in single quotes; -- cgit v1.2.3 From a72bcacba5ee50061099a136f035f65989124665 Mon Sep 17 00:00:00 2001 From: Raul Brito Date: Sat, 9 Nov 2013 19:29:14 +0100 Subject: fix typo --- 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 226eefff..c3317d59 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -11,7 +11,7 @@ This document describes PHP 5+. ```php Date: Fri, 17 Jan 2014 14:38:24 +0800 Subject: php: typo --- 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 c3317d59..e1bb86a0 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -212,7 +212,7 @@ assert($c >= $d); // 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'); assert(1 !== '1'); // Variables can be converted between types, depending on their usage. -- cgit v1.2.3 From 6933d24227ec5a0f220bf897e57d5222eaba0084 Mon Sep 17 00:00:00 2001 From: Geoffrey Liu Date: Sun, 12 Oct 2014 12:24:52 -0700 Subject: Capitalize language names. See #137 --- 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 e1bb86a0..039288a0 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -1,5 +1,5 @@ --- -language: php +language: PHP contributors: - ["Malcolm Fell", "http://emarref.net/"] - ["Trismegiste", "https://github.com/Trismegiste"] -- cgit v1.2.3 From 7458e15cd208982f12ae3a8d04261aaaf8332044 Mon Sep 17 00:00:00 2001 From: tleb Date: Thu, 14 May 2015 21:30:15 +0000 Subject: add ; to php/en --- 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 039288a0..2d4565e0 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -60,7 +60,7 @@ $float = 1.2e3; $float = 7E-10; // Delete variable -unset($int1) +unset($int1); // Arithmetic $sum = 1 + 1; // 2 -- cgit v1.2.3 From 222cfcd15c7539fd4d2340e5e70cbf3f6b6e087b Mon Sep 17 00:00:00 2001 From: Jonathan Klein Date: Thu, 1 Oct 2015 07:37:05 -0400 Subject: All class constants can be accessed statically --- 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 2d4565e0..5cc6a785 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -495,7 +495,9 @@ class MyClass } } +// Class constants can always be accessed statically echo MyClass::MY_CONST; // Outputs 'value'; + echo MyClass::$staticVar; // Outputs 'static'; MyClass::myStaticMethod(); // Outputs 'I am static'; -- cgit v1.2.3 From 087d0619481c4812cae387a4704e9ff91b935ea5 Mon Sep 17 00:00:00 2001 From: Luqi Pan Date: Thu, 1 Oct 2015 16:42:51 -0700 Subject: Aligned the comment block --- 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 2d4565e0..52ea2a95 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -487,7 +487,7 @@ class MyClass * Declaring class properties or methods as static makes them accessible without * needing an instantiation of the class. A property declared as static can not * be accessed with an instantiated class object (though a static method can). -*/ + */ public static function myStaticMethod() { -- cgit v1.2.3 From 0ad95b119d1f0135bf3a9fd55cebf24d63692c11 Mon Sep 17 00:00:00 2001 From: Michele Orselli Date: Fri, 2 Oct 2015 18:24:45 +0200 Subject: adds some new php operators --- php.html.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 52ea2a95..53be5391 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -215,6 +215,14 @@ assert($a !== $d); assert(1 === '1'); assert(1 !== '1'); +// spaceship operator since PHP 7 +$a = 100; +$b = 1000; + +echo $a <=> $a; // 0 since they are equal +echo $a <=> $b; // -1 since $a < $b +echo $b <=> $a; // 1 since $b > $a + // Variables can be converted between types, depending on their usage. $integer = 1; @@ -264,6 +272,18 @@ if (false) { // ternary operator print (false ? 'Does not get printed' : 'Does'); +// ternary shortcut operator since PHP 5.3 +// equivalent of "$x ? $x : 'Does'"" +$x = false; +print($x ?: 'Does'); + +// null coalesce operator since php 7 +$a = null; +$b = 'Does print'; +echo $a ?? 'a is not set'; // prints 'a is not set' +echo $b ?? 'b is not set'; // prints 'Does print' + + $x = 0; if ($x === '0') { print 'Does not print'; -- cgit v1.2.3 From fb43ef2942f29ece285be3e8944c91bde6306095 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:12:15 -0500 Subject: Added example of when string concatenation can also be helpful with combination of strings with html tags as this is important to understand when templating say output code from a database transaction. --- 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 3fcce264..86fb14e5 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -102,6 +102,8 @@ END; // String concatenation is done with . echo 'This string ' . 'is concatenated'; +// Strings concatenation can also be combined with html elements +echo 'This string is' . '' . 'bold with strong tags ' . '.' /******************************** -- cgit v1.2.3 From 63793af2e955f8a8abe698c4a70809cfbff63452 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:54:09 -0500 Subject: Added section on how to declare and initialize both single varible and multiple varibles with the same value. Important concept for large structured programs. Seperated this a little bit. --- php.html.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 86fb14e5..1c2204fd 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,9 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; -// Strings concatenation can also be combined with html elements -echo 'This string is' . '' . 'bold with strong tags ' . '.' +echo 'This string ' . 'is concatenated'; /******************************** -- cgit v1.2.3 From 4e139ae2f528a08eb47427ea790bd176092e1bf0 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:57:39 -0500 Subject: unneeded change fixed --- 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 1c2204fd..d4131992 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,7 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; +echo 'This string ' . 'is concatenated'; /******************************** @@ -689,4 +689,4 @@ 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). +[PSR standards](https://github.com/php-fig/fig-standards). \ No newline at end of file -- cgit v1.2.3 From 960ee4a1856db8eadb96277bb2422edfa8f2a81c Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 23:11:24 -0400 Subject: removing whitespace all over --- 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 93066284..2b1fe1dc 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -515,7 +515,7 @@ class MyClass } } -// Class constants can always be accessed statically +// Class constants can always be accessed statically echo MyClass::MY_CONST; // Outputs 'value'; echo MyClass::$staticVar; // Outputs 'static'; -- cgit v1.2.3