Авторизация
 Регистрация   Войти   Забыли пароль? 

Control Statements: if / else / elseif

:: English Support Forums :: PHP-Fusion Coding Coding Style :: Control Statements: if / else / elseif
Admin  Распечатать сообщение

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in E:\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 E:\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 E:\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.
Загрузить источник  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.

Загрузить источник  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:
Загрузить источник  PHP
  1. <?php
  2.  if ($a != 2) {
  3.   $a = 2;
  4.  }
  5. ?>
else {
$a = 7;
}

Загрузить источник  PHP
  1. <?php
  2.  if ($a != 2) {
  3.   $a = 2;
  4.  }
  5. ?>
elseif ($a == 3) {
$a = 4;
} else {
$a = 7;
}

Загрузить источник  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.
Изменил(а) Admin , 04.06.2013 20:47:00
  Опубликовано 04.06.2013 20:40:46 
 Перейти на форум:   
HTML-code and BB-code for blogs and forums

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


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

Голосования
Что лучше
нравятся
нравятся
100% = [1 Голос]
AMD
AMD
100% = [1 Голос]
не стоит!
не стоит!
100% = [1 Голос]
Да
Да
100% = [1 Голос]
Да
Да
0% = [0 Голосов]
5
5
100% = [1 Голос]
Нравится
Нравится
100% = [1 Голос]
Да!
Да!
200% = [2 Голосов]
ДА
ДА
300% = [3 Голосов]
"ХАЛЯВНЫЕ" СПОСОБЫ ПОСТАВИТЬ ССЫЛКУ
"ХАЛЯВНЫЕ" СПОСОБЫ ПОСТАВИТЬ ССЫЛКУ
100% = [1 Голос]
Сразу много
Сразу много
100% = [1 Голос]
Можно
Можно
100% = [1 Голос]
Да
Да
300% = [3 Голосов]
Да
Да
200% = [2 Голосов]
надо
надо
0% = [0 Голосов]
Всего голосов : 1
Перейти в ветку