


Eight points to note in PHP code architecture, eight points in PHP architecture_PHP tutorial
Eight points to note in PHP code architecture, eight points in PHP architecture
This article summarizes the eight points to note in PHP code architecture. Share it with everyone for your reference, the details are as follows:
I have been writing code for more than 6 years. Look at the previous architecture and look at the current architecture. All have some shortcomings. No matter what, it's always improving. To be honest, I don’t like using things like frameworks. Basically, all frameworks are similar, not much different. To use them, you have to understand the ideas, directory structure, file calling, file naming, code specifications, etc. It’s quite a waste. of time. The architecture can meet a large part of the requirements. The more people it satisfies, the worse the performance. This is one of the main reasons why I don't like to use architecture. Let’s talk about some thoughts on code architecture.
1. Mainly object-oriented, supplemented by process-oriented
php4 is process-oriented, and php5 and later supports object-oriented.
1. Object-oriented programming ideas, for code management, more reasonable planning, better performance, etc.
2. For process code management, the planning is relatively simple, the calling method is more direct and clear, and the efficiency is relatively poor.
Let’s give an example:
Object-oriented is like a software park. If you want to find the location of a certain company, you need to know which building, which floor, and which room it is.
Process-oriented is like a residential area. If you want to find a certain house, you need to know which road and what number.
If the high-rise buildings in the software park are to be turned into residential buildings, more land will be occupied. If the campus is too large, it will not be cheap to find. It would be much more convenient to have a separate consultation room. Therefore, I personally feel that a good architecture must be mainly object-oriented and supplemented by process-oriented.
2. Directory structure planning
This is very important when designing code architecture. It is like a building in a software park. It cannot be built casually, it must be built regularly. Where are the entry files placed, where are the function modules placed, and where are the template files placed. In a word, arrange the configuration files, JS files, php files, module files, CSS files, image files, etc.
3. Single entrance or multiple entrances
The PHP frameworks and CMS that I know so far are basically single-entry. Single entrance or multiple entrances, each has its own advantages. One thing to mention is that single entry is definitely better than multiple entries, regarding URL rewriting.
4. Object-oriented hierarchical design
Under normal circumstances, basically three levels are enough, the bottom class, the basic bottom module class, and the application class of the combined module. If it is a relatively large website, there will be more levels.
5. Database classes should be well planned
This is very important. The ideal way is to use one class for all sql execution. Why is this? This is a long-term plan. In the future, if you build a mysql cluster or use nosql such as memcache, it will be easy to convert. If sql is available everywhere, it will be depressing.
6. Class sharing under multiple second-level domain names
What does it mean? For example, a website has BBS, portal, Weibo. Normal thinking (except discuz, so the second-level domain name points to the same directory) corresponds to three directories, that is, there are three documentroots. The best shared class is Exists independently of the web directory. This way classes can be shared and code redundancy can be reduced.
7. Using template plug-ins
I don’t think it’s good to mix php code and html code, especially if the website is revised, it will crash you. There are many templates that separate php code and html, such as: smarty
8. js code planning
Smarty can separate php and html, jquery and other similar js plug-ins can separate js and html. JS is also a development language, and plug-ins based on JS can also be understood as a language, both object-oriented and process-oriented. If you don't plan it well, the html page will be messy. If you look at the source code, you will find that it is half html and half JS.
Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction Tutorial on PHP Basic Syntax", "Introduction Tutorial on PHP Object-Oriented Programming" and "Summary of PHP Excellent Development Framework"
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- Analysis of key points and precautions for using PHP abstract classes
- Summary of PHP development precautions
- How to use the PHP callback function And notes
- ThinkPHP entry file settings and related notes analysis
- Several notes on using static methods in PHP
- Notes on using the php array merge array_merge() function
- Notes on php5.3
- Methods and precautions for implementing long connections based on PHP
- A summary of precautions for PHP programming

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools