PHP design mode one: Basic programming mode

Source: Internet
Author: User

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.

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