Skip to content

Commit 46ea1ab

Browse files
author
Marius Burkard
committed
- re-factored coding guidelines
1 parent dad105f commit 46ea1ab

File tree

1 file changed

+35
-53
lines changed

1 file changed

+35
-53
lines changed

CODING_NOTES.php.txt

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,65 @@
11
Some guidelines for web development with php.
22
-----------------------------------------------------
33
* Unix Line Breaks Only, NO windows breaks please.
4-
* Tabs set at 4 spaces either as tabs or spaces.
4+
* Tabs to indent lines, NO spaces
55
* no accidental _<?php space before, within or after a file
66
* 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
9-
* Don't use ereg,split and other old function -> gone in php 5.4 or 6 (different information on php.net) http://www.php.net/manual/en/migration53.deprecated.php
10-
* Don't use shorttags. A Shorttag is <? and that is confusing with <?xml -> always <?php
7+
* error_reporting(E_ALL|E_STRICT), yep php5
8+
* Magic quotes is gone, get used to it now. config = magic_quotes_gpc() Everything must be quoted
9+
* Don't use ereg, split and other old function -> gone in php 5.4
10+
* Don't use shorttags. A Shorttag is <? and that is confusing with <?xml -> always usw <?php
1111
* Column names in database tables and database table names are in lowercase
1212
* Classes for the interface are located in interface/lib/classes/ and loaded with $app->uses() or $app->load() functions.
1313
* Classes for the server are located in server/lib/classes/ and loaded with $app->uses() or $app->load() functions.
14-
15-
please mark any section that need review or work on with
16-
// TODO
17-
* Add documentation about access levels (public, private, protected).
14+
* please mark any section that need review or work on with /* TODO: short description */
1815
* Make function / var names on the following way, first word lower, next word(s) first letter upper like. getFirstResult();
19-
20-
Pear coding guidelines
16+
* always a space but NO newline before opening braces, e. g.
17+
class abc {
18+
public function cde() {
19+
if($a == $b) {
20+
return false;
21+
}
22+
}
23+
}
24+
* no spaces after function/method or control names, e. g.
25+
function abc($x, $y) {
26+
if($condition == true) {
27+
$x = 2;
28+
}
29+
}
30+
and NOT
31+
function abc ($x, $y) {
32+
if ( $condition == true ) {
33+
34+
}
35+
}
2136

2237
//*****************************************************************************
2338
// Commenting style
2439
//*****************************************************************************
25-
phpdoc is used for creating and autogenerating the documentation, this means that
26-
some of the comments can be formatted to be included in documentation.
27-
ie the source files are scanned then processed and html docs are created.
2840

2941
The comments break down into the following types
3042
// is uses for removing lines and debug dev etc
31-
//** and //* are used as "sub comments"
3243
/*
33-
is used to comment out blocks
44+
is used to comment out blocks
3445
*/
46+
3547
/** is used to create documentaion
36-
* thats over
37-
* lines
38-
*/
48+
* thats over
49+
* lines
50+
*/
3951

4052
If you need to block out a section then use
4153
/*
4254
function redundant_code(){
43-
something here
55+
something here
4456
}
4557
*/
4658

4759
To block out single lines use // and all // are assumed to be redundant test code and NOT comments
4860

4961
// print_r($foo);
5062

51-
For inline comment use //** and //* eg
52-
53-
//** Decide what do do
54-
switch($decide){
55-
//* blow it up
56-
case 'baloon':
57-
$foo->gas(+1);
58-
// test_pressure(); << inline comment
59-
break;
60-
61-
//* Do default action
62-
default:
63-
do_land();
64-
get_gps();
65-
//* following grant greaceful exit
66-
//basket_exit_crash();
67-
basket_exit();
68-
69-
}
70-
7163
Do not use the phpdoc on every function, eg
7264

7365
/**
@@ -77,25 +69,15 @@ Do not use the phpdoc on every function, eg
7769
*/
7870
>>
7971
function login($user, $pass){
80-
.......
72+
8173
}
8274
<<
83-
as this function explains its self, the following clean code will suffice
75+
as this function is self-explaining, the following clean code will suffice
8476
>>
8577
function login($user, $pass){
86-
.......
78+
8779
}
8880

89-
If you do need to explain a function then put un the summary syntax eg
90-
91-
/** Pass an array of values where third param is bar
92-
* $foo['bar'] = 1; // allow a user
93-
* $foo['bar'] = 2; // destroy user
94-
* $foo['bar'] = -1; // recreate
95-
*/
96-
public function do_something($x, $y, $foo){
97-
... do something interesting
98-
}
9981

10082
//*****************************************************************************
10183
// Where to store custom settings

0 commit comments

Comments
 (0)