diff --git a/language/control-structures/do-while.xml b/language/control-structures/do-while.xml index 0bc2d6447d1c..3a1bca47f13e 100644 --- a/language/control-structures/do-while.xml +++ b/language/control-structures/do-while.xml @@ -7,13 +7,13 @@ do-while loops are very similar to while loops, except the truth expression is - checked at the end of each iteration instead of in the beginning. + checked at the end of each iteration instead of at the beginning. The main difference from regular while loops is that the first iteration of a do-while loop is guaranteed to run (the truth expression is only checked at the end of the iteration), whereas it may not necessarily run with a regular while loop (the truth expression is - checked at the beginning of each iteration, if it evaluates to + checked at the beginning of each iteration; if it evaluates to &false; right from the beginning, the loop execution would end immediately). @@ -40,7 +40,7 @@ do { The above loop would run one time exactly, since after the first - iteration, when truth expression is checked, it evaluates to + iteration, when the truth expression is checked, it evaluates to &false; ($i is not bigger than 0) and the loop execution ends. diff --git a/language/control-structures/elseif.xml b/language/control-structures/elseif.xml index dcfd0cecf04f..d3a5d3b571f2 100644 --- a/language/control-structures/elseif.xml +++ b/language/control-structures/elseif.xml @@ -46,7 +46,7 @@ a is equal to b elseif expression (if any) that evaluates to &true; would be executed. In PHP, it's possible to write else if (in two words) and the behavior would be identical - to the one of elseif (in a single word). The syntactic meaning + to that of elseif (in a single word). The syntactic meaning is slightly different (the same behavior as C) but the bottom line is that both would result in exactly the same behavior. diff --git a/language/control-structures/for.xml b/language/control-structures/for.xml index 0abadadd426a..b3fe2b350578 100644 --- a/language/control-structures/for.xml +++ b/language/control-structures/for.xml @@ -23,7 +23,7 @@ for (expr1; expr2; expr3) loop. - In the beginning of each iteration, + At the beginning of each iteration, expr2 is evaluated. If it evaluates to &true;, the loop continues and the nested statement(s) are executed. If it evaluates to @@ -124,7 +124,7 @@ for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i . " ", $i++); Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty - expressions in for loops comes in handy in many + expressions in for loops comes in handy on many occasions. @@ -142,7 +142,7 @@ endfor; - It's a common thing to many users to iterate through arrays like in the + It's common for many users to iterate through arrays like in the example below. diff --git a/language/control-structures/foreach.xml b/language/control-structures/foreach.xml index a424f4964612..80d32a45dd2e 100644 --- a/language/control-structures/foreach.xml +++ b/language/control-structures/foreach.xml @@ -143,7 +143,7 @@ Dynamic arrays: Please note that array destructuring - via [] is only possible as of PHP 7.1.0 + via [] is only possible as of PHP 7.1.0. @@ -291,9 +291,9 @@ array(4) { - Reference to a $value of the last array element - remain even after the foreach loop. It is recommended - to destroy these using unset. + A reference to the $value of the last array element + remains even after the foreach loop. It is recommended + to destroy it using unset. Otherwise, the following behavior will occur: diff --git a/language/control-structures/include-once.xml b/language/control-structures/include-once.xml index e1cf75245d25..394ef07b759e 100644 --- a/language/control-structures/include-once.xml +++ b/language/control-structures/include-once.xml @@ -4,14 +4,14 @@ include_once - + The include_once expression includes and evaluates the specified file during the execution of the script. - This is a behavior similar to the include expression, + This behavior is similar to the include expression, with the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns &true;. As the name suggests, the file will be included just once. - + include_once may be used in cases where the same file might be included and evaluated more than once during a diff --git a/language/control-structures/include.xml b/language/control-structures/include.xml index 10b95a0943c1..17364f2faa6c 100644 --- a/language/control-structures/include.xml +++ b/language/control-structures/include.xml @@ -83,7 +83,7 @@ echo "A $color $fruit"; // A green apple then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function. - An exception to this rule are magic constants which are evaluated by the parser before the include occurs. @@ -161,15 +161,15 @@ include 'http://www.example.com/file.php?foo=1&bar=2'; Security warning - - Remote file may be processed at the remote server (depending on the file - extension and the fact if the remote server runs PHP or not) but it still + + A remote file may be processed at the remote server (depending on the file + extension and whether or not the remote server runs PHP) but it still has to produce a valid PHP script because it will be processed at the local server. If the file from the remote server should be processed - there and outputted only, readfile is much better + there and outputted only, readfile is a much better function to use. Otherwise, special care should be taken to secure the remote script to produce a valid and desired code. - + See also Remote files, @@ -194,7 +194,7 @@ include 'http://www.example.com/file.php?foo=1&bar=2'; Because include is a special language construct, parentheses are not needed around its argument. Take care when comparing - return value. + the return value. Comparing return value of include @@ -257,15 +257,15 @@ echo $bar; // prints 1 If the file can't be included, &false; is returned and E_WARNING is issued. - + If there are functions defined in the included file, they can be used in the - main file independent if they are before return or after. + main file regardless of whether they are before return or after. If the file is included twice, PHP will raise a fatal error because the functions were already declared. It is recommended to use include_once instead of - checking if the file was already included and conditionally return inside + checking if the file was already included and conditionally returning inside the included file. - + Another way to "include" a PHP file into a variable is to capture the output by using the Output Control diff --git a/language/control-structures/match.xml b/language/control-structures/match.xml index 6735f154d18a..27fd69bfd419 100644 --- a/language/control-structures/match.xml +++ b/language/control-structures/match.xml @@ -86,7 +86,7 @@ string(8) "Teenager" When a match expression is used as a standalone - expression it must be terminated + expression, it must be terminated by a semicolon ;. @@ -110,7 +110,7 @@ string(8) "Teenager" - match arms do not fall-through to later cases the way + match arms do not fall through to later cases the way switch statements do. @@ -123,7 +123,7 @@ string(8) "Teenager" - As switch statements, match + Like switch statements, match expressions are executed match arm by match arm. In the beginning, no code is executed. The conditional expressions are only evaluated if all previous conditional @@ -146,11 +146,11 @@ $result = match ($x) { - + match expression arms may contain multiple expressions - separated by a comma. That is a logical OR, and is a short-hand for multiple + separated by a comma. That is a logical OR, and is a shorthand for multiple match arms with the same right-hand side. - + @@ -186,17 +186,17 @@ $expressionResult = match ($condition) { - Multiple default patterns will raise a + Multiple default patterns will raise an E_FATAL_ERROR error. - + A match expression must be exhaustive. If the - subject expression is not handled by any match arm an + subject expression is not handled by any match arm, an UnhandledMatchError is thrown. - + Example of an unhandled match expression @@ -240,7 +240,7 @@ object(UnhandledMatchError)#1 (7) { - Using match expressions to handle non identity checks + Using match expressions to handle non-identity checks It is possible to use a match expression to handle non-identity conditional cases by using true as the subject @@ -248,7 +248,7 @@ object(UnhandledMatchError)#1 (7) { - Using a generalized match expressions to branch on integer ranges + Using a generalized match expression to branch on integer ranges - Using a generalized match expressions to branch on string content + Using a generalized match expression to branch on string content The switch statement is similar to a series of - IF statements on the same expression. In many occasions, you may - want to compare the same variable (or expression) with many + if statements on the same expression. In situations where + it is necessary to compare the same variable or expression with many different values, and execute a different piece of code depending - on which value it equals to. This is exactly what the - switch statement is for. + on which value it equals, the switch statement is often + more convenient and easier to read. Note that unlike some other languages, the continue statement - applies to switch and acts similar to break. If you + applies to switch and acts similarly to break. If you have a switch inside a loop and wish to continue to the next iteration of the outer loop, use continue 2. - - Note that switch/case does + + Note that switch/case does a loose comparison. - + @@ -126,7 +126,7 @@ i equals 2 evaluated only once and the result is compared to each case statement. In an elseif statement, the condition is evaluated again. If your condition is - more complicated than a simple compare and/or is in a tight loop, + more complicated than a simple comparison and/or is in a tight loop, a switch may be faster. @@ -190,7 +190,7 @@ i is not equal to 0, 1 or 2 - Multiple default cases will raise a + Multiple default cases will raise an E_COMPILE_ERROR error. @@ -244,7 +244,8 @@ B For more complex comparisons, the value &true; may be used as the switch value. - Or, alternatively, if-else blocks instead of switch. + Or, alternatively, if-else blocks + can be used instead of switch.