March 04, 2015 11:26 Source: Techug Editor: Shanli View full textlikes (
0)Reviews
0)ShareTags: PHP, Programming Guide, PHP Open source project
"IT168 information "
1. Read more manuals and source code
There's nothing more to emphasize than reading a manual – You can learn a lot of things just by reading a manual, especially a lot of functions that have a string and an array. There are many useful functions included in these functions, and if you read the manual carefully, you will often find that in the past project development process, many times you are "reinventing the wheel", and in fact you just need a core function to complete the corresponding function. The handbook is your friend. In addition, there are many open source programs that are developed using PHP. Why not study and learn from it? Download a source code for an open source PHP application and read it carefully. Perhaps the larger the project is worth reading, although they may have more complex structures and systems, but there are also more detailed explanations of the document.
2. Write Modular Code
Good PHP code should be a modular code. PHP's object-oriented programming features are particularly powerful tools that can break down your application into functions or methods. You should separate the front-end HTML/CSS/JAVASCRIPT code from the server side of your application as much as possible, and you can follow the MVC (model-View-controller) pattern on any PHP framework.
3. Code Writing Specification
Good PHP code should have a complete code-writing specification. By naming the variables and functions, a unified approach to accessing the database and handling the errors, and the same code indentation, and so on to achieve the programming specifications, so that your code can be more readable.
4. Writing Portable Code
Good PHP code should be portable. You can use PHP's existing features, such as magic quotes and short tags. Try to understand your needs and then write code that is independent and portable by adapting to PHP features.
5. Write Security Code
Good PHP code should be safe. The PHP5 provides excellent performance and flexibility. But the security issue lies entirely with developers. For a professional PHP developer, deep understanding of critical security vulnerabilities is critical, such as cross-site scripting (XSS), cross-station request forgery (CSRF), Code injection vulnerability, and character encoding vulnerability. By using PHP's special functions and functions, such as: Mysql_real_escape_string and so on, you can write safe code.
6. Code Comment
Code comments are an important part of your code. Code comments can tell what the variable or function does, which will be useful in future code maintenance.
7. Use single quotation mark instead of double quotation mark
strings always use single quotes instead of double quotes to avoid performance degradation caused by variables within the PHP search string. Using single quotes instead of double quotation marks to contain strings can be faster. Because PHP searches for a variable in a string surrounded by double quotes, the single quotation mark does not
8. Escape string Output
It is a good practice to use ent_quotes as a parameter to pass to the Htmlspecialchars function to ensure that single quotation marks (') are also converted to HTML entities.
9. Separating string output with commas
Use the Echo statement to output a string separated by commas (,), rather than using the string join operator (.). Performance is better.
10, the output before checking the value of the transmitted
Check the value passed before output $_get[' query ']. You can use the Isset or empty function to check whether a variable is a null value.
Summarize the ten good habits of the great God of PHP