Top ten habits that php programmers must possess-php Tutorial

Source: Internet
Author: User
As the saying goes, the top ten habits that php programmers must possess. as the saying goes, details determine success or failure. developing good habits will be of great benefit to your success. The following small series summarizes the excellent habits of the top ten PHP gods, learning and transforming them into their own habits, so that you can change your mind in minutes.

1,
Read more manuals and source code

Nothing is better than reading PHP DevelopmentMore important things in the manual, you can learn a lot through reading the manual, especially many functions related to strings and arrays. Many useful functions are included in these functions. if you carefully read the manual, you will often find that in the previous project development process, you often "reinvent the wheel ", in fact, you only need a core function to complete the corresponding functions. In addition, there are many open-source programs developed using PHP. why don't you learn from them? Download the source code of an open-source PHP application. read it carefully. Maybe the larger the project, the more worth reading. although they may have more complex structures and systems, there are more detailed explanations.

2. write modular code

Good PHP code should be modular code. PHP's object-oriented programming functions are powerful tools that can break down your applications into functions or methods. You should split the front-end HTML/CSS/JavaScript code from the server of your application as much as possible. you can also follow MVC (Model-View-Controller) on any PHP framework) mode.

3. code writing specifications

Good PHP code should have a complete set of coding specifications. By naming variables and functions, you can use uniform methods to access the database, handle errors, and indent the same code to achieve programming specifications. This makes your code more readable.

4. Write portable code

Good PHP code should be portable. You can use existing php functions, such as magic quotes and short labels. Try to understand your needs, and then write code to make the code INDEPENDENT and portable by adapting to PHP features.

5. write security code

Good PHP code should be safe. PHP5 provides excellent performance and flexibility, but the security problem lies completely with developers. For a professional PHP developer, it is critical to have a deep understanding of major security vulnerabilities, such as cross-site scripting (XSS) and cross-site request forgery (CSRF), code injection, and character encoding vulnerabilities. You can write secure code by using special PHP functions, such as mysql_real_escape_string.

6. code comments

Code annotation is an important part of code. Through code annotation, you can know what the variable or function is, which will be very useful in later code maintenance.

7. use single quotes instead of double quotes

The string always uses single quotes instead of double quotation marks to avoid performance degradation caused by PHP search for variables in the string. Use single quotes instead of double quotes to include strings, which is faster. Because PHP searches for variables in strings enclosed by double quotation marks, but not in single quotes.

8. escape string output

It is a good habit to pass ENT_QUOTES as a parameter to the htmlspecialchars function to ensure that single quotes (') are also converted to HTML entities.

9. use commas to separate string output

Using echo statements to output strings separated by commas (,) is better than using the string concatenation operator.

10. check the sent values before output.

Check the passed value $ _ GET ['query'] before output. The isset or empty function can be used to check whether the variable is null.

PHP Development programmers, do you know? If you understand it, hurry up and add it to your favorites ~~

Recommended Learning: PHP video tutorial

Source: web developers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.