psr1,psr2


Psr1和Psr2读后代码风格整理完成,作为以后代码书写参考


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

namespace Package;

use Footer;
use Hello as Hel;
use OtherVenderOtherPackageBazClass;
use Test;


* Code Style Example
* @auth sonw
* @date 2016-10-18
*/
class CodeStyle extends Footer implements
HelloInterface,
TestTestInterface,
TestNoneInterface
{
public function sampleFunction($a, $test, $m, $b = 'ss')
{
if ($a == $b) {
hel();
} elseif ($a > $b) {
echo 'da';
} else {
echo 'kk';
}
}
public function tryCatch()
{
//catch error
try {
throw new Exception('error');
} catch (FirstException $e) {

} catch (Exception $e) {

}
}

final public static function bar($bar)
{
switch ($bar) {
case 0:
echo 'Fisrt case';
break;
case 1:
echo 'Second case';

case 2:
case 3:
echo 'This a one ';
break;
default:
# code...
echo 'defalt';
break;
}
}

public function cycle($expr)
{
do {

} while ( $expr);
}

public function loop($item)
{
foreach (item as $key => $value) {

}
}
}



$codeStyle = new CodeStyle();
$codeStyle->sampleFunction(
$a,
$b,
$c,
);

//closures
$var1 = new CodeStyle();
$var2 =3;
$closureWithArg = function ($arg1, $arg2) use($var1, $var2) {

}


?>

PHP-FIG