How should design patterns be used in PHP projects?

in the actual project development of PHP, there is little real application of design patterns in business logic. why?

suppose a simple scenario: using yii2 or laravel to develop user management-related functions, most of the time a simple MVC is created, instead of defining the user interface, and then inheriting it, then polymorphism, and then naturally leads to the factory pattern and so on.

however, in the actual project, it seems that MVC is done with one click, and it doesn"t really create its own new pattern classes to apply. In what position should it be used? Or should that pose be used when writing stand-alone projects such as extension components?


this is because you do not have strict requirements on your own code. For example, Event, in laravel is a listener mode. If you use it or not, the effect is the same, but you have his advantage in code maintenance or structure. You are already built in various design patterns with yii2 or laravel, but what you write under this big framework is too simple. Design patterns can only see its advantages in large project structures. If you don't understand it or the code structure is simple, design patterns will only make you feel troublesome


1. Because the framework you use is already designed by design patterns, you don't need to consider design patterns, you just need to write your logic
2. Your business logic is not complex enough, so you don't need to use it. If there is a need to add 5 third-party login methods now, it may be added in the future. What will your code do? If your login is not decoupled from user management, then every time you change the login mode, you have to change user management and log out
3. Then there is the question of language. After all, this is a PHP, a weakly typed language. There are no restrictions on the return of php. You can return whatever you want. Strongly typed languages are not allowed.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be0e68-3152a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be0e68-3152a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?