CODING STANDARDS
From ESource Wiki
Contents |
Indenting and Whitespace
4 spaces, no tabs.
Control Structures
Best described with an example
while(true) {
echo 'one liner statement';
}
A complicated if statement.
if($condition1) {
echo '1st statement';
} else if($condition2) {
echo 'some statement';
} else {
echo 'last statement';
}
Always use the alternate syntax in views
<div>
<?php if($condition): ?>
<span>Some stuff</span>
<?php elseif($condition2): ?>
<span>Some other stuff</span>
<?php endif ?>
</div>
Or a foreach
<?php foreach($res as $item): ?>
<span><?php echo $item?></span><br/>
<?php endforeach ?>
Naming Conventions
- variables - $i_am_some_variable
- classes - Some_Foo_Class
- function - some_function($foo='me', $bar)
PHP Code Tags
- always use <?php ?>, even in views
- for pure php files, we don't need the closing ?> tag.
