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 22:07] – fgm | coding [2020/11/23 17:23] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 45: | Line 45: | ||
| < | < | ||
| </tr> | </tr> | ||
| - | <tr style=" | + | <tr style=" |
| - | | + | |
| { | { | ||
| $ret = action; | $ret = action; | ||
| return $ret; | return $ret; | ||
| - | }</ | + | }</ |
| - | | + | |
| return action; | return action; | ||
| - | }</ | + | }</ |
| - | | + | |
| { | { | ||
| return action; | return action; | ||
| Line 89: | Line 86: | ||
| < | < | ||
| </tr> | </tr> | ||
| - | <tr style=" | + | <tr style=" |
| - | | + | |
| { | { | ||
| // members | // members | ||
| - | }</ | + | }</ |
| - | | + | |
| - | | + | |
| - | | + | |
| { | { | ||
| // members | // members | ||
| Line 115: | Line 108: | ||
| < | < | ||
| </tr> | </tr> | ||
| - | <tr style=" | + | <tr style=" |
| - | | + | |
| { | { | ||
| action1; | action1; | ||
| Line 127: | Line 119: | ||
| { | { | ||
| defaultaction; | defaultaction; | ||
| - | }</ | + | }</ |
| - | | + | |
| action1; | action1; | ||
| } | } | ||
| Line 136: | Line 127: | ||
| else { | else { | ||
| defaultaction; | defaultaction; | ||
| - | }</ | + | }</ |
| - | | + | |
| action1; | action1; | ||
| } elseif ((test3) && (test4)) { | } elseif ((test3) && (test4)) { | ||
| Line 143: | Line 133: | ||
| } else { | } else { | ||
| defaultaction; | defaultaction; | ||
| - | }</ | + | }</ |
| - | | + | |
| action1; | action1; | ||
| } else if (test3) { | } else if (test3) { | ||
| Line 150: | Line 139: | ||
| } else { | } else { | ||
| | | ||
| - | }</ | + | }</ |
| - | | + | |
| <tr> | <tr> | ||
| < | < | ||
| Line 175: | Line 163: | ||
| < | < | ||
| </tr> | </tr> | ||
| - | <tr style=" | + | <tr style=" |
| - | | + | |
| { | { | ||
| case 1: | case 1: | ||
| Line 189: | Line 176: | ||
| defaultaction; | defaultaction; | ||
| break; | break; | ||
| - | }</ | + | }</ |
| - | | + | |
| case 1: | case 1: | ||
| action1; | action1; | ||
| Line 202: | Line 188: | ||
| defaultaction; | defaultaction; | ||
| break; | break; | ||
| - | }</ | + | }</ |
| - | | + | |
| case 1: | case 1: | ||
| action1; | action1; | ||
| Line 215: | Line 200: | ||
| defaultaction; | defaultaction; | ||
| break; | break; | ||
| - | }</ | + | }</ |
| - | | + | |
| case 1: | case 1: | ||
| break; | break; | ||
| Line 225: | Line 209: | ||
| default: | default: | ||
| break; | break; | ||
| - | }</ | + | }</ |
| - | | + | |
| </ | </ | ||
| </ | </ | ||
| Line 601: | Line 584: | ||
| * " | * " | ||
| * 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.1208470070.txt.gz · Last modified: (external edit)
