1 | <?php |
||
5 | class UnexpectedUseOfThis |
||
6 | { |
||
7 | /** |
||
8 | * @return string |
||
9 | */ |
||
10 | public function thisAsArgument($this) |
||
14 | |||
15 | /** |
||
16 | * @return string |
||
17 | */ |
||
18 | public function thisInCatch() |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | public function thisAsLoopVariable() |
||
36 | |||
37 | /** |
||
38 | * @return string |
||
39 | */ |
||
40 | public function thisAsStaticVariable() |
||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public function thisAsGlobalVariable() |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function unsetThis() |
||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function OtherAsArgument($a) |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | public function OtherInCatch() |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | public function OtherAsLoopVariable() |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | public function OtherAsStaticVariable() |
||
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | public function OtherAsGlobalVariable() |
||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | public function unsetOther() |
||
127 | } |
||
128 | ?> |
||
168 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.