Original address: PHP design mode (a): Basic programming mode
Introduction
As the saying goes, "PHP is the best language in the world" because PHP is capable of anything. But in PHP programming, whether you will encounter such confusion: clearly the same requirements, but the previous code is not reusable, slightly modified does not meet the requirements, big change will make the page changed.
Yes, because PHP is capable of anything, but a high degree of flexibility reduces the structure of the code. Although the three-party framework can be used to solve the problem, the root of the problem is the lack of design patterns.
This series of articles will introduce a variety of design patterns.
Object-Oriented Programming
Object-oriented programming, object-oriented programming (OOP) as the most basic design pattern is not a fresh topic, but most of the novice PHP programming is to write journal, various splicing strings, so here is still to mention.
The concept of object-oriented programming is not said here, after all, many people understand, but how to use in PHP?
Suppose you need to display different types of users on the page, such as computer users, mobile users, etc., then you can abstract the "display" into a class, such as:
agent = $_SERVER['HTTP_USER_AGENT']; echo $this->agent; }}$showAgent = new ShowAgent();?>
Debugging Tips
In many PHP default environments, the debug feature is turned off. There is an easy way to turn on debugging and to configure the php.ini file:
Add this code to your code and even require or include it for easy debugging.
Journal Programming
This list of journal programming is not for you to learn, but rather to indicate which programming is not recommended:
This code is not wrong, but can no longer be reused, right? Each time you encounter the same problem, you need to repeat the stitching.
Process-oriented programming
Process-oriented programming was once popular, and its drawbacks were not maintained, such as:
This code is also not wrong, but for a long time, due to the lack of the concept of class, showtotal in a variety of application scenarios lack of flexibility, you still need to rewrite the code.
Summary
It takes a long time to change the programming mind, but remember: the algorithm increases the speed of the program, while the design pattern increases the speed of programming.
The above describes the PHP design mode one: The basic programming mode, including the content, I hope the PHP tutorial interested in a friend to help.