Here is a detailed description
The Theta class file is named after the. class.php, which is called with the Hump method, and the first letter is capitalized, for example Pay.class.php;
The Theta class name and directory _ file name are consistent. For example: The Directory of class name Zend_autoloader is zend/autoloader.class.php;
The name of the theta function uses lowercase letters and underscores. For example: GET_CLIENT_IP;
The Theta method is named using the Hump method, the first letter lowercase or using an underscore "_", such as Listcomment (), _getresource (), usually the method at the beginning of the underscore belongs to the private method;
The name of the theta attribute uses the Hump method, the first letter lowercase or the underscore "_", such as $username,$_instance, where the attribute at the beginning of the underscore is a private property;
Theta constants are named with uppercase letters and underscore "_", such as "Home_url";
Understand digestion:
1. Indentation and length of line
Indent 4 spaces, not tab (some editors can configure a tab to represent multiple spaces, note that they are spaces), and keep about 75-85 characters long per line
2. Control structure
This part of the most easy to ignore, but also affect the code aesthetic most important aspect, the example is very detailed, benefited.
| The code is as follows |
Copy Code |
|
<?php
if ((condition1) | | (Condition2)) {
Action1;
} elseif ((Condition3) && (Condition4)) {
Action2;
} else {
DefaultAction;
}
?>
<?php
Switch (condition) {
Case 1:
Action1;
Break
Case 2:
Action2;
Break
Default
DefaultAction;
Break
}
?>
<?php
if ($condition 1
|| $condition 2)
&& $condition 3
&& $condition 4
) {
code here
}
?>
<?php
$a = $condition 1 && $condition 2
? $foo: $bar;
$b = $condition 3 && $condition 4
? $foo _man_this_is_too_long_what_should_i_do
: $bar;
?>
|
3. Function call
| The code is as follows |
Copy Code |
|
<?php
$var = foo ($bar, $baz, $quux);
$short = foo ($bar);
$long _variable = foo ($baz);
?> |
4. Class name specification
| The code is as follows |
Copy Code |
|
<?php
Class Foo_bar
{
... code goes here
}
?> |
5. Method name Specification (hump named)
| The code is as follows |
Copy Code |
|
<?php
function Foofunction ($arg 1, $arg 2 = ')
{
if (condition) {
Statement
}
return $val;
}
?> |
6. Array definition Specification
| The code is as follows |
Copy Code |
|
<?php
$some _array = Array (
' foo ' => ' Bar ',
' Spam ' => ' ham ',
);
?> |
7. Note
http://pear.php.net/manual/en/standards.sample.php
http://pear.php.net/manual/en/standards.header.php
8.Including Code
Include_once or require_once should be used at all times.
Require_once ' foo.php '