@@ -225,22 +225,14 @@ rewritten to comply with these rules.
225
225
226
226
## Syntax and indentation
227
227
228
- 1. Never use C++ style comments (i.e. ` //` comment). Always use C-style comments
229
- instead. PHP is written in C, and is aimed at compiling under any ANSI-C
230
- compliant compiler. Even though many compilers accept C++-style comments in
231
- C code, you have to ensure that your code would compile with other compilers
232
- as well. The only exception to this rule is code that is Win32-specific,
233
- because the Win32 port is MS-Visual C++ specific, and this compiler is known
234
- to accept C++-style comments in C code.
235
-
236
- 2. Use K&R-style. Of course, we can ' t and don' t want to force anybody to use a
228
+ 1. Use K&R-style. Of course, we can ' t and don' t want to force anybody to use a
237
229
style he or she is not used to, but, at the very least, when you write code
238
230
that goes into the core of PHP or one of its standard modules, please
239
231
maintain the K&R style. This applies to just about everything, starting with
240
232
indentation and comment styles and up to function declaration syntax. Also
241
233
see [Indentstyle](http: //www.catb.org /~esr /jargon /html /I /indent-style.html).
242
234
243
- 3 . Be generous with whitespace and braces. Keep one empty line between the
235
+ 2 . Be generous with whitespace and braces. Keep one empty line between the
244
236
variable declaration section and the statements in a block, as well as
245
237
between logical statement groups in a block. Maintain at least one empty
246
238
line between two functions, preferably two. Always prefer:
@@ -257,14 +249,20 @@ rewritten to comply with these rules.
257
249
if(foo)bar;
258
250
```
259
251
260
- 4 . When indenting, use the tab character. A tab is expected to represent four
252
+ 3 . When indenting, use the tab character. A tab is expected to represent four
261
253
spaces. It is important to maintain consistency in indentation so that
262
254
definitions, comments, and control structures line up correctly.
263
255
264
- 5 . Preprocessor statements (`#if` and such) MUST start at column one. To indent
256
+ 4 . Preprocessor statements (`#if` and such) MUST start at column one. To indent
265
257
preprocessor directives you should put the `#` at the beginning of a line,
266
258
followed by any number of spaces.
267
259
260
+ 5. The length of constant string literals should be calculated via ``strlen()``
261
+ instead of using ``sizeof()-1`` as it is cleared and any modern compiler
262
+ will understand it. Legacy usages of the latter style exists within the
263
+ codebase but should not be refactored, unless larger refactoring around that
264
+ code is taking place
265
+
268
266
## Testing
269
267
270
268
1. Extensions should be well tested using `*.phpt` tests. Read more at
0 commit comments