From 0b78a32686bb45aa0aba9bc5c4ad61fc16b4e1b7 Mon Sep 17 00:00:00 2001 From: Neil Masters Date: Wed, 12 Mar 2014 13:27:40 +0000 Subject: [PATCH 1/4] Update The-Basics.md Adding a suggested change to ternary operators where its not actually necessary to use them but is commonly seen. --- pages/The-Basics.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index f6f3484..68f2d52 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -304,6 +304,19 @@ vs. $a = 5; return ($a == 5) ? 'yay' : 'nope'; // this example will return 'yay' + +It should be noted to save confusion that you do not need to use a ternary operator for returning a boolean value. An example of this would be. + +$a = 3; +return ($a == 3) ? true : false; // Will return true or false if $a == 3 + +vs + +$a = 3; +return ($a == 3); // Will return true or false if $a == 3 + +This can also be said for all operations(===, !==, !=, == etc). + {% endhighlight %} * [Ternary operators](http://php.net/manual/en/language.operators.comparison.php) From 84491f7b06a93beef714d01566e644d1cd00681e Mon Sep 17 00:00:00 2001 From: Neil Masters Date: Wed, 12 Mar 2014 16:25:24 +0000 Subject: [PATCH 2/4] Update The-Basics.md Updated to conform to rest of document and I believe that I have utilized the correct syntax for then highlighters. --- pages/The-Basics.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index 68f2d52..b6866ea 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -305,15 +305,21 @@ vs. $a = 5; return ($a == 5) ? 'yay' : 'nope'; // this example will return 'yay' -It should be noted to save confusion that you do not need to use a ternary operator for returning a boolean value. An example of this would be. +{% endhighlight %} +It should be noted that you do not need to use a ternary operator for returning a boolean value. An example of this would be. + +{% highlight php %} + Date: Thu, 13 Mar 2014 09:56:01 +0000 Subject: [PATCH 3/4] Update The-Basics.md Added section for using brackets for both form and function. I would appreciate a second set of eyes over this to clarify its easy to understand. --- pages/The-Basics.md | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index b6866ea..e3d7708 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -325,6 +325,58 @@ This can also be said for all operations(===, !==, !=, == etc). {% endhighlight %} +#### Utilising brackets with ternary operators for form and function + +When utilising a ternary operator, brackets can play their part to improve code readability and also to include unions within blocks of statements. An example of when there is no requirement to use bracketing is: + +{% highlight php %} + Date: Mon, 2 Jun 2014 23:32:50 +0100 Subject: [PATCH 4/4] Update The-Basics.md Tidying up the wordyness, removing overused and thus redundant variable assignments and improving explanations in replacement for quick & short comments. --- pages/The-Basics.md | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index e3d7708..8a141a7 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -285,11 +285,12 @@ stacked/nested, it is advised to use one per line for readability.