1
1
# PHP coding standards
2
2
3
- This file lists several standards that any programmer adding or changing code in
4
- PHP should follow. Since this file was added at a very late stage of the
5
- development of PHP v3.0, the code base does not fully follow it, but new
6
- features are going in that general direction. Many sections have been rewritten to
7
- use these rules.
3
+ This file lists standards that any programmer adding or changing code in
4
+ PHP should follow. The code base does not yet fully follow it, but new
5
+ features are going in that general direction. Many sections have been
6
+ rewritten to comply with these rules.
8
7
9
8
## Code implementation
10
9
11
10
1 . Document your code in source files and the manual. (tm)
12
11
13
12
2 . Functions that are given pointers to resources should not free them.
14
13
15
- For instance, ` function int mail(char *to, char *from) ` should NOT free to
16
- and/or from.
14
+ For instance, ` function int mail(char *to, char *from) ` should NOT free ` to `
15
+ and/or ` from ` .
17
16
18
17
Exceptions:
19
18
20
19
* The function's designated behavior is freeing that resource. E.g.
21
20
` efree() `
22
21
23
22
* The function is given a boolean argument, that controls whether or not the
24
- function may free its arguments (if true - the function must free its
25
- arguments, if false - it must not)
23
+ function may free its arguments (if true, the function must free its
24
+ arguments; if false, it must not)
26
25
27
26
* Low-level parser routines, that are tightly integrated with the token
28
27
cache and the bison code for minimum memory copying overhead.
29
28
30
29
3 . Functions that are tightly integrated with other functions within the same
31
- module, and rely on each other non-trivial behavior, should be documented as
30
+ module, and rely on each other's non-trivial behavior, should be documented as
32
31
such and declared ` static ` . They should be avoided if possible.
33
32
34
33
4 . Use definitions and macros whenever possible, so that constants have
35
- meaningful names and can be easily manipulated. The only exceptions to this
36
- rule are 0 and 1, when used as ` false ` and ` true ` (respectively). Any other
37
- use of a numeric constant to specify different behavior or actions should be
38
- done through a ` #define ` .
34
+ meaningful names and can be easily manipulated. Any use of a numeric
35
+ constant to specify different behavior or actions should be done through
36
+ a ` #define ` .
39
37
40
38
5 . When writing functions that deal with strings, be sure to remember that PHP
41
39
holds the length property of each string, and that it shouldn't be
@@ -260,35 +258,18 @@ use these rules.
260
258
```
261
259
262
260
4. When indenting, use the tab character. A tab is expected to represent four
263
- spaces. It is important to maintain consistency in indenture so that
261
+ spaces. It is important to maintain consistency in indentation so that
264
262
definitions, comments, and control structures line up correctly.
265
263
266
264
5. Preprocessor statements (`#if` and such) MUST start at column one. To indent
267
265
preprocessor directives you should put the `#` at the beginning of a line,
268
- followed by any number of whitespace .
266
+ followed by any number of spaces .
269
267
270
268
## Testing
271
269
272
- 1. Extensions should be well tested using `*.phpt` tests. Read about that at
270
+ 1. Extensions should be well tested using `*.phpt` tests. Read more at
273
271
[qa.php.net](https: //qa.php.net /write-test.php) documentation.
274
272
275
- ## Folding hooks
276
-
277
- Use `{{{` symbols for the folding mode in Emacs and vim (`set fdm =marker `).
278
- Folding is very useful when dealing with large files because you can scroll
279
- through the file quickly and just unfold the function you wish to work on.
280
- The `}}}` at the end of each function marks the end of the fold, and should
281
- be on a separate line.
282
-
283
- ```c
284
- /* {{{ Returns the absolute value of the number * /
285
- PHP_FUNCTION(abs)
286
- {
287
- ...
288
- }
289
- /* }}} * /
290
- ```
291
-
292
273
## New and experimental functions
293
274
294
275
To reduce the problems normally associated with the first public implementation
@@ -302,8 +283,8 @@ The file labelled `EXPERIMENTAL` should include the following information:
302
283
* Any authoring information (known bugs, future directions of the module).
303
284
* Ongoing status notes which may not be appropriate for Git comments.
304
285
305
- In general new features should go to PECL or experimental branches until there
306
- are specific reasons for directly adding it to the core distribution.
286
+ In general, new features should go to PECL or experimental branches until there
287
+ are specific reasons for directly adding them to the core distribution.
307
288
308
289
## Aliases & legacy documentation
309
290
0 commit comments