Summary of 13 good habits of foreign PHP programmers

Source: Internet
Author: User

That is, the 13 PHP coding habits listed in this article. If you have better suggestions, you are welcome to post them in the comments below this article. I like to learn.
1. When using select to query information from the same database, use a join statement to get all the information you need in a neat manner at a time, instead of writing multiple mysql_query/while/mysql_fetch_array statements.

2. If you call a database connection in multiple files, create a connection. php file to save your connection variables and include the file as needed.

3. For small projects, write all your functions in a file. For large projects, write them in an object and include the file where necessary.

4. If your included files are out of control, you can create an include file that contains all. inc files and include this include file as needed.

5. Compile a document for your code. You will need it when you read the code three months later.

6. Code formatting is nothing more important than readability.

7. Separate the logic and presentation layers.

8. When writing a class, make sure you know when is the best time for coupling and when is the best time for expansion.

9. The interface is your friend.

10. As projects become larger and larger, splitting your code into models, views, and controllers is a super scam.

11. Never output POST and GET data before the HTML Tag is removed,

12. Never trust user input, even if she is your mother.

13. never repeat the class name. Remember, always!

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: 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.