Last active
October 21, 2016 06:16
-
-
Save MasterHans/1acdda82f5b21258a6249e30cf6f4429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Files MUST(ОБЯЗАНЫ) use only <?php and <?= tags. | |
2. Class MUST(ОБЯЗАНЫ) name - StudlyCaps() | |
каждое слово с большой буквы | |
3. Constant MUST(ОБЯЗАНЫ) - MY_CONSTANT_NAME | |
upper case with under score separators (верхний регистр , нижние подчёркивания) | |
const DATE_APPROVED = '2012-06-01'; | |
4. Method names MUST(ОБЯЗАНЫ) - camelCase() | |
(одногорбый верблюд) | |
5. PHP code MUST(ОБЯЗАНЫ) use only UTF-8 without BOM | |
6. Про (side effects) побочные эффекты | |
В php файлах можно делать следующие вещи: | |
а) declaration : объявлением классов, функций, констант, переменных | |
// declaration | |
function foo() | |
{ | |
// function body | |
} | |
б) side effects (побочные эффекты): | |
явное использование require или include: | |
// побочный эффект: подключение файла | |
include "file.php"; | |
изменение настроек ini файла | |
// побочный эффект: изменение настроек | |
ini_set('error_reporting', E_ALL); | |
// side effect: generates output (вывод результатов на экран) | |
echo "<html>\n"; | |
НЕ СЛЕДУЕТ (т.е. не обязательно в определённых обстоятельствах можно забить но придерживаться) | |
использовать а)declaration и б)side effects вместе в одном файле. | |
ПРИМЕР КАК НЕ СЛЕДУЕТ: | |
<?php | |
// side effect: change ini settings | |
ini_set('error_reporting', E_ALL); | |
// side effect: loads a file | |
include "file.php"; | |
// side effect: generates output | |
echo "<html>\n"; | |
// declaration | |
function foo() | |
{ | |
// function body | |
} | |
ПРИМЕР КАК СЛЕДУЕТ: | |
<?php | |
// declaration (описание) | |
function foo() | |
{ | |
// function body | |
// conditional declaration is *not* a side effect (не побочный эфект) | |
if (! function_exists('bar')) { | |
function bar() | |
{ | |
// function body | |
} | |
} | |
7. Свойства | |
Можно выбрать любой $StudlyCaps, $camelCase или $under_score | |
НО придерживаться ПОСЛЕДОВАТЕЛЬНО этого правила в рамках всего кода | |
на уровне | |
vendor-level, package-level, class-level, or method-level | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment