@@ -9,11 +9,11 @@ rewritten to comply with these rules.
9
9
10
10
1 . Document your code in source files and the manual. (tm)
11
11
12
- 1 . PHP is implemented in C99. The optional fixed-width integers from
12
+ 2 . PHP is implemented in C99. The optional fixed-width integers from
13
13
stdint.h (int8_t, int16_t, int32_t, int64_t and their unsigned
14
14
counterparts) must be available.
15
15
16
- 1 . Functions that are given pointers to resources should not free them.
16
+ 3 . Functions that are given pointers to resources should not free them.
17
17
18
18
For instance, ` function int mail(char *to, char *from) ` should NOT free ` to `
19
19
and/or ` from ` .
@@ -30,42 +30,42 @@ rewritten to comply with these rules.
30
30
* Low-level parser routines, that are tightly integrated with the token
31
31
cache and the bison code for minimum memory copying overhead.
32
32
33
- 1 . Functions that are tightly integrated with other functions within the same
33
+ 4 . Functions that are tightly integrated with other functions within the same
34
34
module, and rely on each other's non-trivial behavior, should be documented as
35
35
such and declared ` static ` . They should be avoided if possible.
36
36
37
- 1 . Use definitions and macros whenever possible, so that constants have
37
+ 5 . Use definitions and macros whenever possible, so that constants have
38
38
meaningful names and can be easily manipulated. Any use of a numeric
39
39
constant to specify different behavior or actions should be done through
40
40
a ` #define ` .
41
41
42
- 1 . When writing functions that deal with strings, be sure to remember that PHP
42
+ 6 . When writing functions that deal with strings, be sure to remember that PHP
43
43
holds the length property of each string, and that it shouldn't be
44
44
calculated with ` strlen() ` . Write your functions in such a way so that
45
45
they'll take advantage of the length property, both for efficiency and in
46
46
order for them to be binary-safe. Functions that change strings and obtain
47
47
their new lengths while doing so, should return that new length, so it
48
48
doesn't have to be recalculated with ` strlen() ` (e.g. ` php_addslashes() ` ).
49
49
50
- 1 . NEVER USE ` strncat() ` . If you're absolutely sure you know what you're doing,
50
+ 7 . NEVER USE ` strncat() ` . If you're absolutely sure you know what you're doing,
51
51
check its man page again, and only then, consider using it, and even then,
52
52
try avoiding it.
53
53
54
- 1 . Use ` PHP_* ` macros in the PHP source, and ` ZEND_* ` macros in the Zend part of
54
+ 8 . Use ` PHP_* ` macros in the PHP source, and ` ZEND_* ` macros in the Zend part of
55
55
the source. Although the ` PHP_* ` macros are mostly aliased to the ` ZEND_* `
56
56
macros it gives a better understanding on what kind of macro you're calling.
57
57
58
- 1 . When commenting out code using a ` #if ` statement, do NOT use ` 0 ` only.
58
+ 9 . When commenting out code using a ` #if ` statement, do NOT use ` 0 ` only.
59
59
Instead, use ` "<git username here>_0" ` . For example, ` #if FOO_0 ` ,
60
60
where ` FOO ` is your git user ` foo ` . This allows easier tracking of why
61
61
code was commented out, especially in bundled libraries.
62
62
63
- 1 . Do not define functions that are not available. For instance, if a library is
63
+ 10 . Do not define functions that are not available. For instance, if a library is
64
64
missing a function, do not define the PHP version of the function, and do
65
65
not raise a run-time error about the function not existing. End users should
66
66
use ` function_exists() ` to test for the existence of a function.
67
67
68
- 1 . Prefer ` emalloc() ` , ` efree() ` , ` estrdup() ` , etc. to their standard C library
68
+ 11 . Prefer ` emalloc() ` , ` efree() ` , ` estrdup() ` , etc. to their standard C library
69
69
counterparts. These functions implement an internal "safety-net" mechanism
70
70
that ensures the deallocation of any unfreed memory at the end of a request.
71
71
They also provide useful allocation and overflow information while running
@@ -78,7 +78,7 @@ rewritten to comply with these rules.
78
78
may need to control or free the memory, or when the memory in question needs
79
79
to survive between multiple requests.
80
80
81
- 1 . The return type of "is" or "has" style functions should be ` bool ` ,
81
+ 12 . The return type of "is" or "has" style functions should be ` bool ` ,
82
82
which return a "yes"/"no" answer. ` zend_result ` is an appropriate
83
83
return value for functions that perform some operation that may
84
84
succeed or fail.
@@ -115,7 +115,7 @@ rewritten to comply with these rules.
115
115
jf_n_s_i
116
116
```
117
117
118
- 1 . If they are part of a "parent set" of functions, that parent should be
118
+ 2 . If they are part of a "parent set" of functions, that parent should be
119
119
included in the user function name, and should be clearly related to the
120
120
parent program or function family. This should be in the form of `parent_*`:
121
121
@@ -137,19 +137,19 @@ rewritten to comply with these rules.
137
137
delete_foo_baz
138
138
```
139
139
140
- 1 . Function names used by user functions should be prefixed with `_php_`, and
140
+ 3 . Function names used by user functions should be prefixed with `_php_`, and
141
141
followed by a word or an underscore-delimited list of words, in lowercase
142
142
letters, that describes the function. If applicable, they should be declared
143
143
`static`.
144
144
145
- 1 . Variable names must be meaningful. One letter variable names must be avoided,
145
+ 4 . Variable names must be meaningful. One letter variable names must be avoided,
146
146
except for places where the variable has no real meaning or a trivial
147
147
meaning (e.g. `for (i=0; i<100 ; i++) ...`).
148
148
149
- 1 . Variable names should be in lowercase. Use underscores to separate between
149
+ 5 . Variable names should be in lowercase. Use underscores to separate between
150
150
words.
151
151
152
- 1 . Method names follow the *studlyCaps* (also referred to as *bumpy case* or
152
+ 6 . Method names follow the *studlyCaps* (also referred to as *bumpy case* or
153
153
*camel caps*) naming convention, with care taken to minimize the letter
154
154
count. The initial letter of the name is lowercase, and each letter that
155
155
starts a new `word` is capitalized:
@@ -170,7 +170,7 @@ rewritten to comply with these rules.
170
170
getI()
171
171
```
172
172
173
- 1 . Class names should be descriptive nouns in *PascalCase* and as short as
173
+ 7 . Class names should be descriptive nouns in *PascalCase* and as short as
174
174
possible. Each word in the class name should start with a capital letter,
175
175
without underscore delimiters. The class name should be prefixed with the
176
176
name of the " parent set" (e.g. the name of the extension) if no namespaces
@@ -228,9 +228,9 @@ rewritten to comply with these rules.
228
228
static int php_session_destroy()
229
229
```
230
230
231
- 1 . Main module source file must be named `modulename.c`.
231
+ 2 . Main module source file must be named `modulename.c`.
232
232
233
- 1 . Header file that is used by other sources must be named `php_modulename.h`.
233
+ 3 . Header file that is used by other sources must be named `php_modulename.h`.
234
234
235
235
## Syntax and indentation
236
236
@@ -241,7 +241,7 @@ rewritten to comply with these rules.
241
241
indentation and comment styles and up to function declaration syntax. Also
242
242
see [Indentstyle](http: //www.catb.org /~esr /jargon /html /I /indent-style.html).
243
243
244
- 1 . Be generous with whitespace and braces. Keep one empty line between the
244
+ 2 . Be generous with whitespace and braces. Keep one empty line between the
245
245
variable declaration section and the statements in a block, as well as
246
246
between logical statement groups in a block. Maintain at least one empty
247
247
line between two functions, preferably two. Always prefer:
@@ -258,15 +258,15 @@ rewritten to comply with these rules.
258
258
if(foo)bar;
259
259
```
260
260
261
- 1 . When indenting, use the tab character. A tab is expected to represent four
261
+ 3 . When indenting, use the tab character. A tab is expected to represent four
262
262
spaces. It is important to maintain consistency in indentation so that
263
263
definitions, comments, and control structures line up correctly.
264
264
265
- 1 . Preprocessor statements (`#if` and such) MUST start at column one. To indent
265
+ 4 . Preprocessor statements (`#if` and such) MUST start at column one. To indent
266
266
preprocessor directives you should put the `#` at the beginning of a line,
267
267
followed by any number of spaces.
268
268
269
- 1 . The length of constant string literals should be calculated via ``strlen()``
269
+ 5 . The length of constant string literals should be calculated via ``strlen()``
270
270
instead of using ``sizeof()-1`` as it is clearer and any modern compiler
271
271
will optimize it away. Legacy usages of the latter style exists within the
272
272
codebase but should not be refactored, unless larger refactoring around that
0 commit comments