PHP編碼風格規範
- 2019 年 10 月 3 日
- 筆記
??PHP?????????????????????????????????PHP??????????PSR????PSR-1?PSR-2??????PHP??????????????????????????????????????????????????????????????PSR???????????PSR-1?PSR-2??????????
????PSR
PSR?? | ?? | ?? |
---|---|---|
1 | ?????? | ??PHP??????????????? |
2 | ?????? | ????????????????????? |
3 | ?????? | ?????????????????? |
4 | ?????? | ????????????????????????????? |
6 | ?????? | ????????????????????????????????? |
7 | HTTP?????? | ??HTTP???????? |
PSR-1??????
- ????
???PHP?????<?php?<?=????????????????????<????????? - ???
PHP???????????????????????(??????????????)???????????? - ??
?????????????????????????????????????????????????????????????????????????????????????????????????????????
PSR-2??????
-
PSR-1??PHP???<?php???PSR-2????PHP?????????>?????????????????
-
namespace?????????????use??????????????????????????????use???
-
???????
class?????????extends?implements???????????????????????????????????????????????????????????????????????????????????????implements?????????????({)???????????????????(})????????????????????????????class EarthGame extends Game implements Playable, Savable { //?? }
?????????????????
class EarthGame extends Game implements Playble, Savable { //?? }
-
????
?????????????(public?private?protected)?????????var?????PSR-1????????????:??????????????????????????????????(?????????????) -
????????
?????????????(public?private?protected)?????????abstract?final???static?????????????????????????-
????
????????({)??????????????????(})?????????????(??????????)??????????????????(??????????????)???????????(????)????????????????????????????????????:final public static function generateTile(int $diamondCount, bool $polluted = false) { //??? }
-
????
????????????????????????????????????????????(????????????????)???????????????????????????????????????????????????????({)????????????????????????????????????????????????????????????????public function __construct( int $size, string $name, bool $warparound = false, bool $aliens = false ) { //??? }
-
-
????
??????4????????????????????????????????????Tab????4??????????????????????120???? -
???????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????$earthGanme = new EarthGame( 5, 'earth', true, true ); $earthGame::generateTile(5, true);
-
????
???????(if?for?while?)??????????????????????????????????????????????????????????(??)???????????????????????????????????????????????????????$title = []; for ($x = 0; $x < $diamondCount; $x++) { if ($polluted) { $title[] = new PollutionDecorator(new DiamondDecorator(new Plains())); } else { $title[] = new DiamondDecorator(new Plains()); } }
??if?for??????for?if????????????????????????????????????????????