Introduction to the characteristics of PHP junk code_PHP tutorial

WBOY
Release: 2016-07-15 13:32:47
Original
858 people have browsed it

When we develop a program, we often collect many other people’s program codes on the Internet, but how do we correctly choose a good program code to help us solve the problem? Below we will introduce to you about

If you are not familiar with the software you want to modify, then I suggest you take a good look at the software before making a decision. So how can we conclude that this is junk code without doing in-depth research? Here are 10 signs of PHP spam code for your reference.

PHP junk code 1. Trying to transform the object-oriented model, or modify a certain PHP language feature

If you find a class named Object, it is very likely The author of this software tried to modify the object-oriented model (most likely because he did not understand object-oriented himself), so we can expect that his modifications were not limited to this. When this happens, turn off your phone and hide!

PHP junk code 2. Contains custom global variables

Look for the global keyword or $GLOBALS variable in the code, if the following code is found:

global $database, $my, $mainframe;

This is the infamous global variable. If you can tell what the last two global variables represent, then I guess you are familiar with my code, or you have supernatural powers. If you could also tell me which code would use them, that would be amazing! Anyway, stay away from it.

PHP junk code 3. HTML and SQL can be found everywhere

Look for HTML codes and SQL statements in the code. You should be able to quickly identify whether these codes are should appear here. If you find a file that contains both HTML and SQL, congratulations, you have discovered the worst software!

PHP junk code 4. Overly bloated classes

Look for the three largest class files and see if the class names have clear functions? Let’s take a look at its methods. Are they related to each other? If not, leave screaming!

PHP junk code 5. A large number of public or static variables

If you find that many variables are defined as "public static", then increase your bid Three times that. I don’t need to explain why.

PHP junk code 6. Multi-level inheritance relationships

We should try to avoid more than two levels of inheritance relationships. I spent a lot of time working with objects that had too much irrelevant behavior. If you knew what multi-level inheritance was useful for, I'd buy you a beer.

PHP junk code 7. Trying to use design patterns (just trying)

To know whether the author of the code uses design patterns, just retrieve the most commonly used ones. Yes, such as factory (factory mode), decorator (decoration mode), strategy (strategy mode), etc. If so, you can quickly identify whether the author actually uses these design patterns, or just wants to make the code look interesting. If it's the latter, then leave quickly.

PHP junk code 8. Program disorder under different error levels

A complete application should be able to run normally under all error levels. Use /error_level(.*)/ to find out whether the code has modified the error level. If so, change it to E_STRICT and run it again.

PHP junk code 9. There is a directory called core

When the entire application depends on certain code to run, put this pile of code into a A directory called core would be a good idea. However, aside from having a nice directory name, this approach often indicates poor design.

PHP junk code 10. Use a template language designed by yourself

You must be full of fear of this situation. Because these guys are trying to build their own wheel! If you are not careful about this, you will find that you spend a good part of your day simulating a for loop.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446114.htmlTechArticleWhen we develop a program, we often collect many other people’s program codes on the Internet, but how to correctly How about choosing a good program code to help you solve the problem? ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!