This article is intended for readers who want to understand the object-oriented and process-oriented programming methods in PHP, including beginners and veterans. Suppose that the reader is familiar with PHP and class applications to a certain extent. Introduction: "real talents have accurate comments
Target readers
This article is intended to understand PHP's object-oriented and process-oriented programming methods, including beginners and veterans. Suppose that the reader is familiar with PHP and class applications to a certain extent.
Introduction
"A real genius has the ability to accurately review and determine information that is risky and conflicting. -- Qiu Gill"
When you use many programming languages, you can only use object-oriented or process-oriented programming methods. In PHP, you can freely choose or mix. Currently, most PHP programmers use process-oriented methods, because parsing WEB pages is very "procedural" (from one tag to another ). It is natural to process code in the embedded process in HTML, so PHP programmers usually use this method.
If you are new to PHP, writing code with a process-oriented style may be your only choice. But if you often go to PHP forums and message groups, you should see articles about "objects. You may also see tutorials on how to write object-oriented PHP code. Or you may have downloaded some ready-made class libraries and tried to instantiate the objects and application class methods in them-although you may not really understand why these classes can work, or why is it necessary to apply an object-oriented method to achieve the effect.
Should the "object-oriented" style or "process-oriented" style be applied? Each party has its own support. Discussions like "objects are inefficient" or "objects are great" are also heard. This article does not try to easily determine which of the two methods has the best advantage, but to find out the advantages of each method.
The following is a process-oriented code example:
The following is an example of object-oriented code:
myPrint(); ?>
If you want to know some basic "object-oriented" knowledge, please use Google search and there are many excellent articles on the Internet.
Who writes code like this?
To understand why this topic has become a fuse for the forum, let's take a look at some of the true examples of each camp. Let's take a look at "process fanatics" and "object fanatics ". Let's see if they seem familiar.
Process craze
The process fever was criticized by computer teachers in class, because this method has not been applied to more abstract implementation methods. Supporting the process-oriented viewpoint, "it can work !" It cannot improve the programming degree and grade. After graduation, they may find a job, write drivers, file systems, or other underlying-biased programming, with their focus on speed and code refining.
The extreme example of "process mania" is to resist objects and abstract them. They are always thinking about how to make the program run faster, regardless of whether others can understand their code. They often regard programming as competitions rather than team sports. Apart from PHP, their favorite programming languages are C and assembly. In the PHP world, they may develop the PECL module and contribute efficient code.