aboutsummaryrefslogtreecommitdiff
path: root/documentation/coding_standards/php_coding_standards.txt
blob: b7adc5dd9b407a0d14a88df4357028ff3b396cf5 (plain)
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
*** PHP CODING STANDARDS ***

These are the coding standards for Elgg.  All core development and bundled
plugins are required to be in this format. Plugin developers are strongly
encouraged to adopt these standards.

* 	Unix line endings.

* 	Hard tabs, 4 character tab spacing.

* 	No PHP shortcut tags ( <? or <?= or <% ).

* 	PHPDoc comments on functions and classes (all methods; declared properties
	when appropriate).

* 	Mandatory wrapped {}s around any code blocks. 
		Bad:
		if (true) 
			foreach($arr as $elem) 
				echo $elem;
	
		Good:
		if (true) {
			foreach ($arr as $elem) {
				echo $elem;
			}
		}

* 	Name standalone functions using underscore_character().

* 	Name classes using CamelCase() and methods using lowerCamelCase().

* 	Name globals and constants in ALL_CAPS (ACCESS_FRIENDS, $CONFIG).

* 	Use underscores / camel case to separate standard English words in
	functions, classes, and methods. (get_default_site(), ElggUser->isLoggedIn()).

* 	Space functions like_this($required, $optional = TRUE).

* 	Space keywords and constructs like this: if (FALSE) { ... }.

* 	Correctly use spaces, quotes, and {}s in strings: 
		Bad (hard to read, misuse of quotes and {}s): 
		echo 'Hello, '.$name."!  How is your {$time_of_day}?";
		
		Good:
		echo "Hello, $name!  How is your $time_of_day?"; 

* 	Line lengths should be reasonable.  If you are writing lines over 100 
	characters on a line, please revise the code.

* 	Use // or /* */ when commenting.

* 	No closing PHP tag (?>) at EOF unless after a heredoc. (Avoids problems with 
	trailing whitespace. Required after heredoc by PHP.)