How php uses AOP
This article will explain in detail how php uses AOP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
What is AOP?
In application development, we often find that we need a lot of functions, which are often scattered at multiple points in the code, but these points actually have nothing to do with the actual business. For example, before performing some special tasks, we need to make sure that the user is logged in. We call these special people "cross-cutting concerns". Let's take a look at the definition of "cross-cutting concerns" through Wikipedia.
In computer science, "cross-cutting concerns" means "sectional (or directional) programming". These relationships cannot be well decomposed from other systems (framework design or some implementations), resulting in code duplication, meaningful dependencies in the system, or both.
Now you should have a basic understanding of "horizontal relationships". Let's see what they look like in the code.
Suppose a scenario where you are the editor of a blog site. You need to log in to the site, then create posts, verify posts, edit posts, and so on. If you are not logged in, then you should go directly to the login interface. To ensure that these behaviors are safe, any of the above actions need to be validated as follows.
The copy code is as follows: