User Tools

Site Tools


coding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
coding [2008/04/17 22:08] fgmcoding [2010/09/17 20:13] fgm
Line 45: Line 45:
     <th>ZF</th>     <th>ZF</th>
     </tr>     </tr>
-  <tr style="white-space: pre; font-family: monospace;"> +  <tr style="white-space: pre; font-family: monospace;"><td style="vertical-align: top">private function foo($bar, $baz = 'qux'
-    <td style="vertical-align: top">private function foo($bar, $baz = 'qux'+
   {   {
   $ret = action;   $ret = action;
   return $ret;   return $ret;
-  }</td> +  }</td><td style="vertical-align: top">function _g2_foo($bar, $baz = 'qux') {
-    <td style="vertical-align: top">function _g2_foo($bar, $baz = 'qux') {+
   return action;   return action;
-}</td> +}</td><td colspan="2" style="vertical-align: top">private function foo($bar, $baz = 'qux')
-      <td colspan="2" style="vertical-align: top">private function foo($bar, $baz = 'qux')+
     {     {
         return action;         return action;
Line 89: Line 86:
     <th>ZF</th>     <th>ZF</th>
     </tr>     </tr>
-  <tr style="white-space: pre; font-family: monospace;"> +  <tr style="white-space: pre; font-family: monospace;"><td style="vertical-align: top">class Foo
-    <td style="vertical-align: top">class Foo+
   {   {
   // members   // members
-  }</td> +  }</td><td style="vertical-align: top">N.A: no classes</td><td>?</td><td style="vertical-align: top">class Foo
-    <td style="vertical-align: top">N.A: no classes</td> +
-      <td>?</td> +
-    <td style="vertical-align: top">class Foo+
 { {
     // members     // members
Line 115: Line 108:
     <th>ZF</th>     <th>ZF</th>
     </tr>     </tr>
-  <tr style="white-space: pre; font-family: monospace;"> +  <tr style="white-space: pre; font-family: monospace;"><td style="vertical-align: top">if (test1 || test2)
-    <td style="vertical-align: top">if (test1 || test2)+
   {   {
   action1;   action1;
Line 127: Line 119:
   {   {
   defaultaction;   defaultaction;
-  }</td> +  }</td><td style="vertical-align: top">if (test1 || test2) {
-    <td style="vertical-align: top">if (test1 || test2) {+
   action1;   action1;
 } }
Line 136: Line 127:
 else { else {
   defaultaction;   defaultaction;
-}</td> +}</td><td style="vertical-align: top">if ((test1) || (test2)) {
-    <td style="vertical-align: top">if ((test1) || (test2)) {+
     action1;     action1;
 } elseif ((test3) && (test4)) { } elseif ((test3) && (test4)) {
Line 143: Line 133:
 } else { } else {
     defaultaction;     defaultaction;
-}</td> +}</td><td style="vertical-align: top">if (test1) {
-    <td style="vertical-align: top">if (test1) {+
     action1;     action1;
 } else if (test3) { } else if (test3) {
Line 150: Line 139:
 } else { } else {
    defaultaction;    defaultaction;
-}</td> +}</td></tr>
-    </tr>+
   <tr>   <tr>
     <td>&nbsp;</td>     <td>&nbsp;</td>
Line 628: Line 616:
   }   }
 </code> </code>
 +
  
 ===== Drupal-specific: Naming functions and constants within modules ===== ===== Drupal-specific: Naming functions and constants within modules =====
- 
- 
  
   * Drupal mandates some function names, notably, for module "mymodule":   * Drupal mandates some function names, notably, for module "mymodule":
- 
     * 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 = 'bar';   const SOME_CONSTANT = 'bar';
- 
- 
  
   // ... 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::foo(My_Module::SOME_CONSTANT); My_Module::foo(My_Module::SOME_CONSTANT);
- 
 </code> </code>
- 
- 
coding.txt · Last modified: 2020/11/23 17:23 by 127.0.0.1