coding
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
coding [2008/04/17 21:56] – fgm | coding [2020/11/23 17:23] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 15: | Line 15: | ||
====== Indenting ====== | ====== Indenting ====== | ||
+ | |||
Line 35: | Line 36: | ||
===== Function Declarations ===== | ===== Function Declarations ===== | ||
- | |||
- | |||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
$ret = action; | $ret = action; | ||
- | |||
return $ret; | return $ret; | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
return action; | return action; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
return action; | return action; | ||
- | |||
}</ | }</ | ||
- | |||
</tr> | </tr> | ||
- | |||
</ | </ | ||
- | |||
</ | </ | ||
- | |||
- | |||
Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Never use parentheses around the returned value (ZF: it can break code if a method is later changed to return by reference). | Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Never use parentheses around the returned value (ZF: it can break code if a method is later changed to return by reference). | ||
- | |||
- | |||
For long argument lists or long argument names, appropriate line wrapping may be used, like: | For long argument lists or long argument names, appropriate line wrapping may be used, like: | ||
- | |||
<code php> | <code php> | ||
- | |||
public function someFunctionWithALongName( | public function someFunctionWithALongName( | ||
- | |||
$firstParamsHasALongNameToo, | $firstParamsHasALongNameToo, | ||
- | |||
$secondParamIsAlmostWorse | $secondParamIsAlmostWorse | ||
- | |||
$notForgettingOtherDefaults = 0) | $notForgettingOtherDefaults = 0) | ||
- | |||
{ | { | ||
- | |||
$ret = action; | $ret = action; | ||
- | |||
return $ret; | return $ret; | ||
- | |||
} | } | ||
- | |||
</ | </ | ||
+ | |||
===== Class Declarations ===== | ===== Class Declarations ===== | ||
- | |||
- | |||
- | |||
- | |||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
// members | // members | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
- | + | ||
- | | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
// members | // members | ||
- | |||
}</ | }</ | ||
- | |||
</tr> | </tr> | ||
- | |||
</ | </ | ||
- | |||
</ | </ | ||
- | |||
- | |||
- | |||
===== if / then / else ===== | ===== if / then / else ===== | ||
- | |||
- | |||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
action1; | action1; | ||
- | |||
} | } | ||
- | |||
elseif (test3 && test2) | elseif (test3 && test2) | ||
- | |||
{ | { | ||
- | |||
action2; | action2; | ||
- | |||
} | } | ||
- | |||
else | else | ||
- | |||
{ | { | ||
- | |||
defaultaction; | defaultaction; | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
action1; | action1; | ||
- | |||
} | } | ||
- | |||
elseif (test3 && test4) { | elseif (test3 && test4) { | ||
- | |||
action2; | action2; | ||
- | |||
} | } | ||
- | |||
else { | else { | ||
- | |||
defaultaction; | defaultaction; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
action1; | action1; | ||
- | |||
} elseif ((test3) && (test4)) { | } elseif ((test3) && (test4)) { | ||
- | |||
action2; | action2; | ||
- | |||
} else { | } else { | ||
- | |||
defaultaction; | defaultaction; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
action1; | action1; | ||
- | |||
} else if (test3) { | } else if (test3) { | ||
- | |||
| | ||
- | |||
} else { | } else { | ||
- | |||
| | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ | </ | ||
- | |||
</ | </ | ||
- | |||
- | |||
Note that for ZF, the code sample supplied in the doc contradicts the doc text. Reference is made to the text. The rules and sample do not specify parenthesing for multiple tests in a clause. | Note that for ZF, the code sample supplied in the doc contradicts the doc text. Reference is made to the text. The rules and sample do not specify parenthesing for multiple tests in a clause. | ||
- | |||
- | |||
For OSInet, long tests must be wrapped to align readably. Although ZF does not mention this, the line length requirement makes it likely too. | For OSInet, long tests must be wrapped to align readably. Although ZF does not mention this, the line length requirement makes it likely too. | ||
- | |||
===== switch ===== | ===== switch ===== | ||
- | |||
- | |||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
{ | { | ||
- | |||
case 1: | case 1: | ||
- | |||
action1; | action1; | ||
- | |||
break; | break; | ||
- | |||
- | |||
case 2: | case 2: | ||
- | |||
action2; | action2; | ||
- | |||
break; | break; | ||
- | |||
- | |||
default: | default: | ||
- | |||
defaultaction; | defaultaction; | ||
- | |||
break; | break; | ||
- | + | | |
- | | + | |
- | + | ||
- | | + | |
case 1: | case 1: | ||
- | |||
action1; | action1; | ||
- | |||
break; | break; | ||
- | |||
- | |||
case 2: | case 2: | ||
- | |||
action2; | action2; | ||
- | |||
break; | break; | ||
- | |||
- | |||
default: | default: | ||
- | |||
defaultaction; | defaultaction; | ||
- | |||
break; | break; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
case 1: | case 1: | ||
- | |||
action1; | action1; | ||
- | |||
break; | break; | ||
- | |||
- | |||
case 2: | case 2: | ||
- | |||
action2; | action2; | ||
- | |||
break; | break; | ||
- | |||
- | |||
default: | default: | ||
- | |||
defaultaction; | defaultaction; | ||
- | |||
break; | break; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
case 1: | case 1: | ||
- | |||
break; | break; | ||
- | |||
- | |||
case 2: | case 2: | ||
- | |||
break; | break; | ||
- | |||
- | |||
default: | default: | ||
- | |||
break; | break; | ||
- | + | }</ | |
- | }</ | + | |
- | + | ||
- | | + | |
</ | </ | ||
- | |||
</ | </ | ||
- | |||
===== General table ===== | ===== General table ===== | ||
- | |||
- | |||
^ Category ^ OSInet | ^ Category ^ OSInet | ||
- | |||
^ Spacing | ^ Spacing | ||
- | |||
^ ... terminal | n.a. ||| ... and a single space after the closing parenthesis. | | ^ ... terminal | n.a. ||| ... and a single space after the closing parenthesis. | | ||
- | |||
^ Bracing | ^ Bracing | ||
- | |||
^ ... control, opening | The opening brace is written on the line below the structure. | n.a. || The opening brace is written on the same line as the conditional statement. | ^ ... control, opening | The opening brace is written on the line below the structure. | n.a. || The opening brace is written on the same line as the conditional statement. | ||
- | |||
^ ... control, closing | = ZF | n.a. || The closing brace is always written on its own line. | | ^ ... control, closing | = ZF | n.a. || The closing brace is always written on its own line. | | ||
- | |||
^ ... classes | = ZF | n.a. || The brace is always written on the line underneath the class name. | | ^ ... classes | = ZF | n.a. || The brace is always written on the line underneath the class name. | | ||
+ | |||
Line 443: | Line 232: | ||
====== Function Calls ====== | ====== Function Calls ====== | ||
- | |||
- | |||
^ Category | ^ Category | ||
- | |||
^ name to ( | no space |||| | ^ name to ( | no space |||| | ||
- | |||
^ ( to arg1 | no space |||| | ^ ( to arg1 | no space |||| | ||
- | |||
^ arg to , | no space |||| | ^ arg to , | no space |||| | ||
- | |||
^ , to arg | usually 1 space. May vertically align for block-related function calls | 1 space ||| | ^ , to arg | usually 1 space. May vertically align for block-related function calls | 1 space ||| | ||
- | |||
^ arg to ) | no space |||| | ^ arg to ) | no space |||| | ||
- | |||
^ ) to ; | no space |||| | ^ ) to ; | no space |||| | ||
- | |||
- | |||
ZF rules for this are implied by the example in the A.4.5.2 section. | ZF rules for this are implied by the example in the A.4.5.2 section. | ||
- | |||
- | |||
- | |||
====== Arrays ====== | ====== Arrays ====== | ||
- | |||
- | |||
Spacing, one-liner: **identical** | Spacing, one-liner: **identical** | ||
- | |||
- | |||
- | |||
Spacing, indented: **Different** | Spacing, indented: **Different** | ||
- | |||
- | |||
Note that if the line spans longer than 80 characters (often the case with form and menu declarations), | Note that if the line spans longer than 80 characters (often the case with form and menu declarations), | ||
- | |||
- | |||
<code php> | <code php> | ||
- | |||
$form[' | $form[' | ||
- | |||
( | ( | ||
- | |||
'# | '# | ||
- | |||
'# | '# | ||
- | |||
'# | '# | ||
- | |||
'# | '# | ||
- | |||
'# | '# | ||
- | |||
); | ); | ||
- | |||
</ | </ | ||
- | |||
- | |||
Additional comma: identical. | Additional comma: identical. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
====== Including Code ====== | ====== Including Code ====== | ||
Line 525: | Line 273: | ||
This means that including can make use of the autoload mechanism, which can be more efficient under caching than using require_once with conditional content. | This means that including can make use of the autoload mechanism, which can be more efficient under caching than using require_once with conditional content. | ||
+ | |||
Line 543: | Line 292: | ||
====== File formatting ====== | ====== File formatting ====== | ||
- | |||
- | |||
^ Feature | ^ Feature | ||
- | |||
| <% %> tags | No | No | | <% %> tags | No | No | ||
- | |||
| <? ?> tags | No | No | | <? ?> tags | No | No | ||
- | |||
| Closing ?> | No | Should be omitted | | Closing ?> | No | Should be omitted | ||
- | |||
| Indenting | | Indenting | ||
- | |||
| Tabs | No | No | | Tabs | No | No | ||
- | |||
| Line length | as ZF | | Line length | as ZF | ||
- | |||
| Line termination | | Line termination | ||
- | |||
| __HALT_COMPILER() | unspecified | | __HALT_COMPILER() | unspecified | ||
- | |||
- | |||
The rule regarding the closing ?> tag is only applicable to " | The rule regarding the closing ?> tag is only applicable to " | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
====== Comments, inline doc ====== | ====== Comments, inline doc ====== | ||
- | |||
- | |||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</ | </ | ||
- | |||
<td style=" | <td style=" | ||
- | |||
< | < | ||
- | |||
</ | </ | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
* Short description for file | * Short description for file | ||
- | |||
* | * | ||
- | |||
* Long description for file (if any)... | * Long description for file (if any)... | ||
- | |||
* | * | ||
- | |||
* LICENSE: Some license information | * LICENSE: Some license information | ||
- | |||
* | * | ||
- | |||
* @copyright | * @copyright | ||
- | |||
* @license | * @license | ||
- | |||
* @version | * @version | ||
- | |||
* @link | * @link | ||
- | |||
* @since | * @since | ||
- | |||
*/</ | */</ | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
* Short description for class | * Short description for class | ||
- | |||
* | * | ||
- | |||
* Long description for class (if any)... | * Long description for class (if any)... | ||
- | |||
* | * | ||
- | |||
* @copyright | * @copyright | ||
- | |||
* @license | * @license | ||
- | |||
* @version | * @version | ||
- | |||
* @link | * @link | ||
- | |||
* @since | * @since | ||
- | |||
* @deprecated Class deprecated in Release 2.0.0 | * @deprecated Class deprecated in Release 2.0.0 | ||
- | |||
| | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<td> | <td> | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</td> | </td> | ||
- | |||
</ | </ | ||
- | |||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||
Line 769: | Line 412: | ||
====== Naming Conventions ====== | ====== Naming Conventions ====== | ||
+ | |||
+ | |||
Line 791: | Line 436: | ||
< | < | ||
- | |||
<table class=" | <table class=" | ||
- | |||
<col span=" | <col span=" | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr style=" | <tr style=" | ||
- | |||
< | < | ||
- | + | | |
- | | + | |
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr style=" | <tr style=" | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr style=" | <tr style=" | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr style=" | <tr style=" | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
{ | { | ||
- | |||
const SOME_CONSTANT = ' | const SOME_CONSTANT = ' | ||
- | |||
}</ | }</ | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
const SOME_CONSTANT = ' | const SOME_CONSTANT = ' | ||
- | |||
}</ | }</ | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
protected _someFieldTwo; | protected _someFieldTwo; | ||
- | |||
public | public | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
protected _someFieldTwo; | protected _someFieldTwo; | ||
- | |||
public someFieldThree;</ | public someFieldThree;</ | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</td> | </td> | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</li> | </li> | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</td> | </td> | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</td> | </td> | ||
- | |||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
- | |||
< | < | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</li> | </li> | ||
- | |||
< | < | ||
- | |||
<ul> | <ul> | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
< | < | ||
- | |||
</ul> | </ul> | ||
- | |||
</li> | </li> | ||
- | |||
</ul> | </ul> | ||
- | |||
</li> | </li> | ||
- | |||
</ul> | </ul> | ||
- | |||
</td> | </td> | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
<td style=" | <td style=" | ||
- | |||
</tr> | </tr> | ||
- | |||
</ | </ | ||
- | |||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
===== Variables ===== | ===== Variables ===== | ||
- | + | Variables naming following the rules for functions and methods. Exceptions: | |
- | + | ||
- | Variables naming following the rules for functions and methods. | + | |
- | + | ||
- | + | ||
- | + | ||
- | Exceptions: | + | |
- | + | ||
* existing libraries or APIs are not renamed. Facade APIs may be used until existing libraries match the new format | * existing libraries or APIs are not renamed. Facade APIs may be used until existing libraries match the new format | ||
- | |||
* the standard variable $ret should be used for all return values. Always use it to return a value, instead of directly returning the latest instruction result. This helps with a typical debugger configuration: | * the standard variable $ret should be used for all return values. Always use it to return a value, instead of directly returning the latest instruction result. This helps with a typical debugger configuration: | ||
- | |||
* some Hungarian notation is used: | * some Hungarian notation is used: | ||
- | |||
* the name of " | * the name of " | ||
- | |||
* http:// | * http:// | ||
- | |||
* naming resulting from external objects applies the rule by pieces. Example: | * naming resulting from external objects applies the rule by pieces. Example: | ||
- | |||
* GTK widgets are named < | * GTK widgets are named < | ||
- | |||
* GTK signals are called < | * GTK signals are called < | ||
- | |||
* Related callbacks are called on_< | * Related callbacks are called on_< | ||
- | |||
* Example: on_fmMain_destroy is | * Example: on_fmMain_destroy is | ||
- | |||
* " | * " | ||
- | |||
* " | * " | ||
- | |||
* " | * " | ||
- | |||
* Rationale: forcing CamelCaps for the standard naming convention would result in onFmMainDestroy, | * Rationale: forcing CamelCaps for the standard naming convention would result in onFmMainDestroy, | ||
- | |||
- | |||
- | |||
===== Functions and Methods ===== | ===== Functions and Methods ===== | ||
- | |||
- | |||
* Since PHP4 support is not required, visibility (private, protected) settings on class members are recommended when using PHP5 class constructions. | * Since PHP4 support is not required, visibility (private, protected) settings on class members are recommended when using PHP5 class constructions. | ||
- | |||
* functions or methods returning unsafe values are prefixed by " | * functions or methods returning unsafe values are prefixed by " | ||
- | |||
* " | * " | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
===== Constants ===== | ===== Constants ===== | ||
- | |||
- | |||
As of 01/01/2007, see table above. Note that the PHP builtins " | As of 01/01/2007, see table above. Note that the PHP builtins " | ||
- | |||
- | |||
Previously, the format was: | Previously, the format was: | ||
- | |||
<code php> | <code php> | ||
- | |||
define(' | define(' | ||
- | |||
</ | </ | ||
- | |||
- | |||
This style of coding is now considered obsolete (even under Drupal conventions, | This style of coding is now considered obsolete (even under Drupal conventions, | ||
<code php> | <code php> | ||
- | |||
class G2 | class G2 | ||
- | |||
{ | { | ||
- | |||
// don't forget the PHPdoc here | // don't forget the PHPdoc here | ||
- | |||
const VERSION = ' | const VERSION = ' | ||
- | |||
} | } | ||
- | |||
</ | </ | ||
- | |||
===== Drupal-specific: | ===== Drupal-specific: | ||
- | |||
- | |||
* Drupal mandates some function names, notably, for module " | * Drupal mandates some function names, notably, for module " | ||
- | |||
* default theme functions must be named theme_mymodule_foo | * default theme functions must be named theme_mymodule_foo | ||
- | |||
* hook_foo implementations must be named mymodule_foo | * hook_foo implementations must be named mymodule_foo | ||
- | |||
* Beyond that, all other functions in a module should be defined as static public methods of a class named like the module, like: | * Beyond that, all other functions in a module should be defined as static public methods of a class named like the module, like: | ||
- | |||
<code php> | <code php> | ||
- | |||
// don't forget the PHPdoc comments here | // don't forget the PHPdoc comments here | ||
- | |||
class My_Module | class My_Module | ||
- | |||
{ | { | ||
- | |||
// and here | // and here | ||
- | |||
const SOME_CONSTANT = ' | const SOME_CONSTANT = ' | ||
- | |||
- | |||
// ... and here too | // ... and here too | ||
- | |||
static public function foo($op) | static public function foo($op) | ||
- | |||
{ | { | ||
- | |||
// do something and return | // do something and return | ||
- | |||
} | } | ||
- | |||
} | } | ||
- | |||
- | |||
// ..which can be invoked as: | // ..which can be invoked as: | ||
- | |||
My_Module:: | My_Module:: | ||
- | |||
</ | </ | ||
- | |||
- |
coding.1208469419.txt.gz · Last modified: 2020/11/23 17:23 (external edit)