PHP code specification, php code specification
Naming specification Θ Class files have the suffix .class.php, are named using camel case, and the first letter is capitalized, for example Pay.class.php; Θ The class name and directory_file name are consistent. For example: the directory of the class name Zend_Autoloader is Zend/Autoloader.class.php; Θ functions are named using lowercase letters and underscores. For example: get_client_ip; Θ Methods are named using camel case, with the first letter lowercase or underscore "_", such as listComment(), _getResource(). Usually methods starting with an underscore are private methods; Θ Attributes are named using camel case, with the first letter lowercase or underscore "_", such as $username, $_instance. Usually attributes starting with an underscore are private attributes; Θ Constants are named with capital letters and underscores "_", such as "HOME_URL"; common nouns 1>List noun (singular), such as listApple, we know at a glance that we are reading a list of apples. We do not need to write getApples or listApples or readApples - because we stipulate that get is generally used to read a single data, such as getApple.listApples does not add We also know that s is to get a list of apples (make sure to shorten the variable naming as much as possible); 2>get noun (singular); 3>The noun Total means the total number of something. Such as expenseTotal; 4>found: Indicates whether a certain value has been found; 5> success or ok: whether an operation was successful; 6>done: Whether a certain project is completed; 7>error: Whether an error occurred; 8>result:The returned result code refactoring 1. Try to keep the code in the function or method body within one screen. 2. Unused methods in the class are randomly deleted. 3. To modify methods in other people’s classes, you need to sign them. 4. Write a readme file in each module (for more complex business descriptions or code descriptions). 5. Try to let each class do its own thing and each function do one thing.Common codes Use && or || to simplify operations Before simplification:
$a =1;
$b = 0;
if (isset( $a )){
$b =1;
print ( $b . "n" );
}
if ( $b !=0){
print ( $b . "n" );
}
|
Simplified:
$a =1;
$b = 0;
isset( $a ) && ( $b =1) && print ( $b . "n" );
$b == 0 || print ( $b . "n" );
|
Obviously the code looks neater and simpler!
When judging "==", we may write "==" as "=". It is difficult for us to debug such bugs. Therefore, put the constant in front and the compiler can judge it. Before:
$a = 1;
if ( $a = 1){
echo '$a == 1' ;
}
|
:
$a = 1;
if (1 = $a ){
echo '$a == 1' ;
}
|
Obviously, if the constant is placed in front, the compiler will be able to determine the error.
Formal format:
$a = 1;
if (1 == $a ){
echo '$a == 1' ;
}
|
lookup table method Before:
/*错误码:4,5,7,8的时候返回状态1,错误码是1,3,6返回状态2*/
$error = 4;
$state = 0;
if ( $error == 4 || $error == 5 || $error == 7 || $error == 8){
$state = 1;
}
if ( $error == 1 || $error == 3 || $error == 6){
$state = 2;
}
echo "$state n" ;
|
after:
/*错误码:4,5,7,8的时候返回状态1,错误码是1,3,6返回状态2*/
$error = 4;
$state = 0;
$arr = array (4 => 1, 5 => 1, 7 => 1, 8 => 1, 1 => 2, 3 => 2, 6 => 2);
isset( $arr [ $error ]) && ( $state = $arr [ $error ]);
echo "$state n" ;
|
Obviously the code is more concise, clearer, easier to understand, and faster!

如何撰写一份完美的PHP程序员求职简历在竞争激烈的就业市场中,一份出色的简历对于求职者来说是至关重要的。对于PHP程序员来说,撰写一份完美的简历尤为重要,因为简历不仅是展示自己技能和经验的窗口,也是吸引雇主注意力的关键。本文将从头到尾详解如何撰写一份完美的PHP程序员求职简历。第一步:选择简洁而具有吸引力的简历模板选择一份简洁而具有吸引力的简历模板是撰写简历

提高求职成功率:写一份优秀的PHP程序员求职简历的技巧在现代社会中,求职已经成为每个毕业生面临的一项重要任务。当谈到求职时,简历是最重要的一环。一份优秀的简历可以为你赢得面试的机会,甚至决定你能否成功获得工作。特别对于PHP程序员这样一个高度竞争的职位来说,如何写一份出众的求职简历,成为每个求职者的关键问题。下面我将分享一些写一份优秀的PHP程序员求职简历的

如何写出一份令雇主眼前一亮的PHP程序员求职简历在竞争激烈的求职市场上,编写一份出色的简历尤为重要。作为PHP程序员,除了令人印象深刻的工作经历和技能,一份简历中也需要体现出你对编程的热爱和扎实的专业知识。本文将介绍一些技巧和代码示例,帮助你编写一份令雇主眼前一亮的PHP程序员求职简历。简洁明了的个人信息简历的个人信息部分应该包括你的姓名、联系方式和个人网站

抢眼的PHP程序员求职简历技巧:如何与其他候选人脱颖而出随着互联网行业的快速发展,PHP程序员也成为了求职市场上的热门岗位之一。然而,越来越多的人选择了PHP作为自己的职业发展方向,这就使得竞争变得更加激烈。在这样的情况下,如何让自己的求职简历脱颖而出,成为雇主眼中的香饽饽,是每个PHP程序员都需要思考的问题。首先,一个好的求职简历应该清晰、简明地展示你的技

PHP程序员的高薪逆袭之路随着互联网的快速发展,计算机科学领域的需求不断增加。在这个时代,需要具备编程技能的人才是最受欢迎的。而PHP作为一种常用的编程语言,为程序员们提供了一条高薪逆袭的道路。本文将介绍PHP程序员如何通过学习PHP以及相关技术,走向高薪逆袭之路,并附上一些代码示例。一、掌握PHP基础知识要成为一名优秀的PHP程序员,首先需要掌握PHP的基

探索写作技巧:如何撰写一份引人注目的PHP程序员求职简历在当今竞争激烈的就业市场中,一份引人注目的求职简历对于PHP程序员来说尤为重要。一个好的简历不仅能够吸引雇主的眼球,还能展示你的技能和经验。本文将探索一些写作技巧,帮助你撰写一份出色的PHP程序员求职简历,并附上代码示例,突出你的专业能力。简洁明了的格式简历的格式应该简洁明了,使得雇主能够快速浏览你的关

在当今竞争激烈的就业市场中,如何让自己在众多求职者中脱颖而出成为了一个非常重要的问题。尤其对于PHP程序员来说,良好的求职简历能够直接影响到是否能够得到面试的机会。本文将为大家详细介绍如何写出一份让你脱颖而出的PHP程序员求职简历。首先,一个好的求职简历应该包含以下几个重要部分:个人信息、求职意向、教育背景、工作经历、技能特长和个人项目经验等。我们将逐个部分

连接HR的关键一步:如何在PHP程序员求职简历中体现你的价值HR在招聘过程中繁忙而又短暂的一瞥中,通过简历来评估和筛选应聘者。在众多求职者中脱颖而出并吸引HR的目光,就需要在简历中展示自己的价值和能力。对于PHP程序员来说,在简历中突出自己的技术实力和项目经历至关重要。下面将介绍几个关键的元素,以及如何通过代码示例来体现自己的价值。技术技能清单在简历的技能栏


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
