Project

General

Profile

StandardsNaming » History » Version 2

Vasily Bezruchkin, January 30, 2013 07:00

1 1 Vasily Bezruchkin
h1. Naming Conventions
2
3 2 Vasily Bezruchkin
{{>TOC}}
4
5 1 Vasily Bezruchkin
h2. Classes
6
7
Classes should be given descriptive names. Avoid using abbreviations where possible. Use upper case letters as word separators (CamelCase), lower case for the rest of a word. Don't use underbars.
8
9
<pre><code class="php">
10
class Name
11
{
12
}
13
14
class SomeCompoundName
15
{
16
}
17
</code></pre>
18
19
20
h2. Functions and Methods
21
22
Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized.
23
24
h2. Constants
25
26
Constants should always be all-uppercase, with underscores to separate words. We highly recommend to use a prefix for the constants. It's a common practice to use *IA_* for Subrion CMS project constants.
27
28
*Note:* The true, false and null constants are excepted from the all-uppercase rule, and must always be lowercase.
29
30
h2. Global Variables
31
32
All the global variables are stored in the $GLOBALS array. All the words in the name are uppercased with underbars as separators. E.g. $GLOBALS['MY_GLOBAL_VAR'].
33
34
35
h2. Hook Names
36
37
The name of hooks should be intuitively obvious and should be show where hook is placed.
38
39
Recommendation name of hook:
40
41
<pre>
42
typePartFileWhereWhat
43
</pre>
44
45
* *type* - the type of hook (php | smarty). It could be PHP or SMARTY hook.
46
* *part* - the part of script (front | admin). In what part of script the hook.
47
* *file* - the name of file in where hook is placed.
48
* *where* - the place of any part of file. (after | before).
49
* *what* - the part of file.
50
51
Examples:
52
_phpFrontHeaderBeforeListingFieldsDisplay_ - It is the common PHP hook in the front end and it is placed before listings fields display action.