Download pdf version - ShnfuCarver 1.0 documentation
Transcript
ShnfuCarver Documentation, Release 1.0 <?php $result = $this->callSomeFunction (’param1’, ’second’, true ); $second_result = $this->callSomeOtherFunction(’parameter2’, ’third’, false); $last_result = $this->callSomeFunction (’3’, ’verrrrrrylong’, true ); ?> 1.1.4 Coding Method • Always use long tags <?php ?> instead of short tags <? ?>. • Perl/shell style comments (#) are discouraged. • The constructor should mainly include class initialization. Do not put in too much action. • Do not use PHP code (e.g. echo or print) to output the html tag. • Use === instead of == if possible. • Do not use magic numbers. • Do not do exact comparison between float numbers. • Avoid embedded assignment. This could lead to misunderstanding. • Use single quotes ’ for strings if no variable expansion. • Put each class in a single file. • Use namespace for clear naming, especially for library. • Try not to create global variables, which may enhance the relation of modules and introduce unexpected behavior. • Do not use parentheses for statements. (require_once, include, echo, return...) • Code must be E_STRICT-compatible. This means that it must not produce any warnings or errors when PHP’s error reporting level is set to E_ALL | E_STRICT (or E_ALL in PHP 5.4.x). 1.1.5 Including Files When unconditionally including a class or library file, use require_once. When conditionally including a class file (for example, factory methods), use include_once. Either of these will ensure that class files are included only once. They share the same file list, so a file included by require_once will not be included again by include_once. 1.1.6 Comment A good program should be understood even without comments. But proper comments could make the reading easier. You do not need to write comments everywhere in the code if the code is in good style. The comment should appear in the following situation: 1. Some complicated algorithm. 2. Where misunderstanding could happen. 3. Some tricks that others may not notice. 4. Any codes where others may not understand or even you may forget the meaning after a few days. All comments should be written in English, and should in a clear way describe the commented block of code. 4 Chapter 1. Coding Standards