Skip to content

Commit 9775888

Browse files
committed
[skip ci] Amend coding style
Drop irrelevant rule about // comments since PHP is C99 + GNU extensions Add rule about strlen() usage for constant string length calculation
1 parent 01c2383 commit 9775888

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

CODING_STANDARDS.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,14 @@ rewritten to comply with these rules.
225225

226226
## Syntax and indentation
227227

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
237229
style he or she is not used to, but, at the very least, when you write code
238230
that goes into the core of PHP or one of its standard modules, please
239231
maintain the K&R style. This applies to just about everything, starting with
240232
indentation and comment styles and up to function declaration syntax. Also
241233
see [Indentstyle](http://www.catb.org/~esr/jargon/html/I/indent-style.html).
242234

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
244236
variable declaration section and the statements in a block, as well as
245237
between logical statement groups in a block. Maintain at least one empty
246238
line between two functions, preferably two. Always prefer:
@@ -257,14 +249,20 @@ rewritten to comply with these rules.
257249
if(foo)bar;
258250
```
259251

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
261253
spaces. It is important to maintain consistency in indentation so that
262254
definitions, comments, and control structures line up correctly.
263255

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
265257
preprocessor directives you should put the `#` at the beginning of a line,
266258
followed by any number of spaces.
267259

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+
268266
## Testing
269267

270268
1. Extensions should be well tested using `*.phpt` tests. Read more at

0 commit comments

Comments
 (0)