commit | author | age
|
b64955
|
1 |
Some guidelines for web development with php. |
P |
2 |
----------------------------------------------------- |
316369
|
3 |
* Unix Line Breaks Only, NO windows breaks please. |
P |
4 |
* Tabs set at 4 spaces either as tabs or spaces. |
|
5 |
* no accidental _<?php space before, within or after a file |
|
6 |
* every php file starts and end with <?php ?> no spaces before or after |
|
7 |
* error_reporting(E_ALL|E_STRICT) , yep php5 |
|
8 |
* Magic quotes is gone in php6, get used to it now. config = magic_quotes_gpc() Everything must be quoted |
b64955
|
9 |
|
3eeed9
|
10 |
please mark any section that need review or work on with |
316369
|
11 |
// TODO |
3eeed9
|
12 |
* Add documentation about access levels (public, private, protected). |
B |
13 |
* Make function / var names on the following way, first word lower, next word(s) first letter upper like. getFirstResult(); |
b64955
|
14 |
|
P |
15 |
Pear coding guiidelines |
|
16 |
|
|
17 |
//***************************************************************************** |
|
18 |
// Commenting style |
|
19 |
//***************************************************************************** |
|
20 |
phpdoc is used for creating and autogenerating the documentation, this means that |
|
21 |
some of the comments can be formatted to be included in documentation. |
|
22 |
ie the source files are scanned then processed and html docs are created. |
|
23 |
|
|
24 |
The comments break down into the following types |
|
25 |
// is uses for removing lines and debug dev etc |
|
26 |
//** and //* are used as "sub comments" |
|
27 |
/* |
|
28 |
is used to comment out blocks |
|
29 |
*/ |
|
30 |
/** is used to create documentaion |
|
31 |
* thats over |
|
32 |
* lines |
|
33 |
*/ |
|
34 |
|
|
35 |
If you need to block out a section then use |
|
36 |
/* |
|
37 |
function redundant_code(){ |
|
38 |
something here |
|
39 |
} |
|
40 |
*/ |
|
41 |
|
|
42 |
To block out single lines use // and all // are assumed to be redundant test code and NOT comments |
|
43 |
|
|
44 |
// print_r($foo); |
|
45 |
|
72a844
|
46 |
For inline comment use //** and //* eg |
b64955
|
47 |
|
P |
48 |
//** Decide what do do |
|
49 |
switch($decide){ |
|
50 |
//* blow it up |
|
51 |
case 'baloon': |
|
52 |
$foo->gas(+1); |
|
53 |
// test_pressure(); << inline comment |
|
54 |
break; |
|
55 |
|
|
56 |
//* Do default action |
|
57 |
default: |
|
58 |
do_land(); |
|
59 |
get_gps(); |
|
60 |
//* following grant greaceful exit |
|
61 |
//basket_exit_crash(); |
|
62 |
basket_exit(); |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
Do not use the phpdoc on every function, eg |
|
67 |
|
|
68 |
/** |
72a844
|
69 |
* Login a user |
b64955
|
70 |
* @param string user username |
P |
71 |
* @param string password of user |
|
72 |
*/ |
|
73 |
>> |
|
74 |
function login($user, $pass){ |
|
75 |
....... |
|
76 |
} |
|
77 |
<< |
72a844
|
78 |
as this function explains its self, the following clean code will suffice |
b64955
|
79 |
>> |
P |
80 |
function login($user, $pass){ |
|
81 |
....... |
|
82 |
} |
|
83 |
|
|
84 |
If you do need to explain a function then put un the summary syntax eg |
|
85 |
|
|
86 |
/** Pass an array of values where third param is bar |
72a844
|
87 |
* $foo['bar'] = 1; // allow a user |
b64955
|
88 |
* $foo['bar'] = 2; // destroy user |
P |
89 |
* $foo['bar'] = -1; // recreate |
|
90 |
*/ |
|
91 |
public function do_something($x, $y, $foo){ |
|
92 |
... do something interesting |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
|