
Copyright © 2009 Cédric Delfosse - Mandriva
| Revision History | ||
|---|---|---|
| Revision $Revision: 4266 $ | $Date: 2009-06-17 18:23:12 +0200 (Wed, 17 Jun 2009) $ | $Author: cdelfosse $ |
Abstract
Coding conventions for the PHP code of all MDS components
Table of Contents
This document sets the coding conventions for the PHP code of all MDS components (like the MMC web interface for example).
Convention from http://pear.php.net/manual/en/standards.php apply too.
Indentation: use 4 spaces per indentation level, no tabs allowed.
Encoding: the source code must always use the UTF-8 encoding.
For long html code, templates and views prefer using "short PHP tags":
<body>
<h1><?= $title ?></h1>
<ul>
<? foreach ($arr as $value) { ?>
<li><?= $value ?></li>
<? } ?>
</ul>
</body>
Code is more explicit and preserve html code source indentation.
block "for", "function", "switch", "if",etc... always end with opening braces on the same line.
if ($val == value) {
echo $val;
} else {
return -1;
}
foreach ($arrParam as $singleItem) {
print $singleItem;
}
Function with long args (more than one line size)
myFunction($value1,
$value2,
$morevalue4,
$val5);
They are written in english.
They always start with a capitalized first word.
There is always a space between the // and the begin of the comment. // and /* are fine. Don't use #.
All functions must have a correct doxygen header.
ClassName : CapitalizedWords
functionName : mixedCase for all function name
_membersValue : member value of a class begin with a "_"
All possible PHP errors, warnings and notices must be fixed in
the PHP code. Use these lines in your php.ini file when working on the code to find
them all:
error_reporting = E_ALL
display_errors = On
Here is the header that must be used:
/**
* (c) 2004-2007 Linbox / Free&ALter Soft, http://linbox.com
* (c) 2007-2009 Mandriva, http://www.mandriva.com
*
* $Id$
*
* This file is part of Mandriva Management Console (MMC).
*
* MMC is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MMC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MMC. If not, see <http://www.gnu.org/licenses/>.
*/