Skip to end of metadata
Go to start of metadata

Here are a list of coding conventions we gathered during the php5 to 4 conversion to make the code more php4 friendly. Please review with corrections/feedback.

  • All object assignments have to be explicitly by reference (for new or singleton or just plain assignment)
  • pass by reference for foreach loops - please do not use pass by reference for values in foreach loop. if you have to use the following
  • Need require_once now for all evals and variable class names
  • Please use CRM_Utils_System::getClassName($object) for getting correct class name (with correct CASE) instead of get_class($object)
  • Please populate the array CRM_Utils_System::$php4SpecialClassName. When u have a class name with components consisting 2 words which are together. For example. CRM_Admin_Form is a regular class name with 3 components and each component is a single word (CRM is allowed). but CRM_Admin_Form_MobileProvider is a special case since the last component MobileProvider is 2 words. hence we need ot make an entry in the above array as an array element ('mobileprovider' => 'MobileProvider')
  • Do not use references within a foreach loop (unless u know what u r doing)
  • Unique names of static variables across the class.
    Please use unique names for static variables across the class. These could be static members or static variables within methods. The reason being the script converter.php converts all the static variables for a class to a global variable $[CLASS_NAME][STATIC_VAR_NAME] and hence the variables collide.
  • Please do not use instanceof in the code. use is_a instead.
  • We should not use more that one deferencing for an object within a function call
    $object1->method1()->method2();
    where method1() returns an object and method2 is called on it.
  • PHP4 does not allow default parameter as reference.

Example.

Labels
  • None

Creative Commons License
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Share Alike 3.0 United States Licence.