Переключатель дизайна
Bordur2-Bogatyr

Language: English (en)
 Russian Russian   English English 

Control Statements: if / else / elseif

:: English Support Forums :: PHP-Fusion Coding Coding Style :: Control Statements: if / else / elseif
Admin  Print Post

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 20

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 21

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\search_bbcode_include.php on line 39

Control Statements if / else / elseif
PHP-Fusion Coding Style PHP-Fusion version 7.02.00



Control statements based on the if and elseif constructs must have a single space before the
opening parenthesis of the condiEonal and a single space amer the closing parenthesis.
Within the condiEonal statements between the parentheses, operators must be separated by
spaces for readability. Inner parentheses are encouraged to improve logical grouping for larger
condiEonal expressions.
The opening brace is wriLen on the same line as the condiEonal statement. The closing brace is
always wriLen on its own line. Any content within the braces must be indented using one tab.
Download source  PHP
  1. <?php
  2.  if ($a != 2) {
  3.   $a = 2;
  4.  }
  5. ?>


If the condiEonal statement causes the line length to exceed the maximum line length and has
several clauses, you may break the condiEonal into mulEple lines. In such a case, break the line
prior to a logic operator, and pad the line such that it aligns under the .rst character of the
condiEonal clause. The closing parent in the condiEonal will then be placed on a line with the
opening brace, with one space separaEng the two, at an indentaEon level equivalent to the
opening control statement.

Download source  PHP
  1. <?php
  2.  if (($a == $b)
  3.   && ($b == $c)
  4.   || (MyClass::myFunction() == $d)
  5.  ) {
  6.   $a = $d;
  7.  }
  8. ?>


The intenEon of this laLer declaraEon format is to prevent issues when adding or removing clauses
from the condiEonal during later revisions.
For "if" statements that include "elseif" or "else", the formaRng convenEons are similar to the "if"
construct. The following examples demonstrate proper formaRng for "if" statements with "else"
and/or "elseif" constructs:
Download source  PHP
  1. <?php
  2.  if ($a != 2) {
  3.   $a = 2;
  4.  }
  5. ?>
else {
$a = 7;
}

Download source  PHP
  1. <?php
  2.  if ($a != 2) {
  3.   $a = 2;
  4.  }
  5. ?>
elseif ($a == 3) {
$a = 4;
} else {
$a = 7;
}

Download source  PHP
  1. <?php
  2.  if (($a == $b)
  3.  && ($b == $c)
  4.  || (MyClass::myFunction() == $d)
  5.  ) {
  6.  $a = $d;
  7.  } elseif (($a != $b)
  8.   || ($b != $c)
  9.  ) {
  10.   $a = $c;
  11.  } else {
  12.   $a = $b;
  13.  }
  14. ?>


PHP allows statements to be wriLen without braces in some circumstances. This coding standard
makes no differenEaEon All "if", "elseif" or "else" statements must use braces.
Edited by Admin on 04.06.2013 20:47:00
  Posted on 04.06.2013 20:40:46 
 Jump to Forum:   
HTML-code and BB-code for blogs and forums

<a href="https://php-fusion.vveb.ws/forum/viewthread.php?lang=en&thread_id=149">Control Statements: if / else / elseif : Control Statements: if / else / elseif</a>


[url=https://php-fusion.vveb.ws/forum/viewthread.php?lang=en&thread_id=149]Control Statements: if / else / elseif : Control Statements: if / else / elseif[/url]

Голосования
Сколько тем надо показывать на главной?
ОСОБЫЕ "ВИРУСНЫЕ" СПОСОБЫ
ОСОБЫЕ "ВИРУСНЫЕ" СПОСОБЫ
0% = [0 Votes]
25
25
0% = [0 Votes]
30
30
0% = [0 Votes]
35
35
0% = [0 Votes]
40
40
0% = [0 Votes]
Всего голосов : 4
Перейти в ветку