Summary of 13 good habits of foreign PHP programmers

  • 2020-05-16 06:25:16
  • OfStack

These are the 13 PHP coding habits listed in this article. If you have better Suggestions, please feel free to post them in the comments later in this article. I am a curious person
1. When using select to query information from the same database, use one join statement to get all the information you need in a neat way. Do not write multiple mysql_query/while/mysql_fetch_array statements.

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

3. For small projects, write all your functions in a single file. For large projects, write them in objects, and include the file where you need it.

4. If your include file gets out of control, create an include file that contains all the.inc files, and then include the include file where you need it.

5. Document your code that you'll need when you look at it three months from now.

Nothing is more important than readability in code layout.

Separate the logic from the presentation layer.

8. When writing a class, make sure you know when the best time to couple it and when the best time to extend it.

Interface is your friend.

10. Breaking up your code into models, views, and controllers is a super con artist as your project gets bigger and bigger.

11. Never output POST and GET data without stripping the HTML tags.

12. Never trust input from a user, even if it's your mother.

Never repeat the class name, remember, is forever!

Related articles: