What you should know when writing PHP now
First of all, you should be using PHP 5.3 or above. If the PHP version is below this, it is time to upgrade. I recommend using the latest version if possible.
You should have read PHP The Right Way. This article contains a lot of content and can be expanded. You need to know most of the terms and concepts.
1. PSR
The idea behind the group is for project representatives to talk about the commonalities between our projects and find ways we can work together.
I have mentioned PSR (PHP Standard Recommendation) many times in previous articles and during discussions with colleagues. Many people think that PSR only does insignificant things such as standardizing coding style, but it is actually much more than that.
PSR's series of standard documents are drafted and voted on by php-fig (PHP Framework Interop Group). Among the voting members are authors of some mainstream frameworks and extensions, including Laravel, Symfony, Yii, etc.
According to its official website, the purpose of this organization is not to tell you what you should do, but to negotiate and agree with each other among some mainstream frameworks. But I believe that you will always use these frameworks and extensions.
PSR has currently approved 6 documents:
0: Automatic loading (mainly for versions without namespaces before PHP 5.3)
1: Coding specifications
2: Coding style recommendations
3: Log results
4: Automatic loading is more detailed (there is a big change after the namespace appears)
7 :HTTP message interface
Currently in draft, there are PSR-5 (PHPDoc Standard), PSR-6 (Cache), etc. 5 and 6 are not on the list above because they have not yet been voted on.
I believe that as the standards continue to be updated, you will find that studying these conventions is also very beneficial to you, although you may not necessarily abide by everything.
Nobody in the group wants to tell you, as a programmer, how to build your application.
2. Composer
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
composer is different from Pear and Pecl. It is not only used for Installing extensions, and more importantly, defines a method for implementing and managing extensions in a modern PHP framework. Similar to npm of node.js and pip of Python, but does more than the above. The core of composer is to implement standard installation of extensions and automatic loading of classes. Through the packagist.org platform, countless extension components can be easily introduced. Currently, the more well-known PHP extensions can be installed through composer. The call only needs to load an autoload.php file. Composer registers an automatic loading method through the spl_autoload_register method to load extension classes and files. Of course, Composer also made an optimization during this process. We all know that PHP imports files through include and require, which is actually not good-looking to write. PHP 5.3 provides namespaces, which have nothing to do with file import. However, composer implements PSR-4 (PSR-0 on older versions of PHP). When using use, the method implemented by calling spl_autoload_register loads the required classes when calling. The writing method is similar to Python's import, which is both beautiful and functional. It comes to the role of on-demand loading and lazy loading.
3. php-cs-fixer
The PHP Coding Standards Fixer tool fixes most issues in your code when you want to follow the PHP coding standards as defined in the PSR-1 and PSR-2 documents.
The function of this tool is to format your code according to PSR-1 and PSR-2 specifications, and some optional coding styles are Symfony specifications.
This is actually not worth talking about originally. I just recently saw .php_cs files in several open source frameworks. I was curious and found out about this project after further research. Some people may think that there is no need to worry about coding style. I can't tell you the benefits. If you think programming is more than just a job, then it's like cleaning your room. A dirty room won't affect your eating and sleeping, but a clean one will look more comfortable. If you want to cooperate with others, then this matter is even more important.
4. PsySH
A runtime developer console, interactive debugger and REPL for PHP.
PsySH is an interactive runtime for PHP similar to Python's IDLE environment. I discovered this in Laravel, and the function of artisan tinker in Laravel 5 is implemented through it. Laravel 4 uses another project: boris.
This is mainly useful when testing some simple functions and features of PHP. If you encounter some uncertain things, such as the use of empty, you can use it to do some testing.
5. Some frameworks and components
Framework
What I prefer is Laravel. Currently, the company is using Yii2. I am concerned about Symfony and Phalcon (implemented in C language). What to use and what not to use mainly comes down to preference, and sometimes you can’t help but make your own choice, but it’s not a bad idea to do some research and learn more about it.
When mentioning Laravel, many people will immediately think of Ruby on Rails. I think imitating or plagiarizing is not the main purpose. The main purpose is to provide developers with a better tool. Fortunately, Laravel has a different routing control (without Action suffix or prefix), a useful ORM (Eloquent), a useful template engine (Blade), or a relatively good-looking document ( If the community sees it) etc.
Powerful is sometimes criticized for being huge, but this is because you need to understand the mid- and long-term planning of your project, the current size of the project, and the future size and carrying capacity.
The core implementation of Larval is a container (Container) and PHP's reflection class (ReflectionClass) (the same is true for Yii 2). To understand this, while reading more articles and documents, you can also look at the source code.
Symfony 2 provides many components. http-kernel and http-foundation are also inherited and used directly in Laravel. It is worth knowing and learning.
CodeIgniter is a small but powerful framework. Although CI is not developed using Composer components, versions later than 3.0 also add support for Composer (this is nothing more than adding an additional vendor directory and introducing autoload.php files).
ORM
ORM or Active Record I think is still needed. Some people may think that PHP is just a template engine and SQL should be written by hand. Don't be bothered by these words.
The implementation of Active Record in CodeIgniter is very lightweight, but for the size of CI itself, it is already very useful.
I like Eloquent implemented by Laravel very much, and it can also be integrated into other projects. Symfony 2 uses Doctrine, and this project is also worthy of attention. Yii 2 also has its own set of implementation methods.
Template engine
The template engine needs to do three things:
1. Output of variable values (echo),
2. Conditional judgment and looping (if...else, for, foreach, while)
3. Introduced or inherited from other files
The Blade implemented by Laravel is a relatively lightweight and easy-to-use template engine. However, it is currently not very easy to introduce it into other frameworks. When I was free, I tried to introduce it into Yii 2. Now it is just a simple implementation. I hope to extract the parsing part of Blade separately and make a lightweight implementation later. A search on Github found someone doing the same thing.
Yii 2 seems to be more recommended to use native PHP to write, but it also provides extensions that support Smarty and Twig. Symfony 2 uses Twig. Twig and Symfony, as well as the php-cs-fixer mentioned above, are all works of SensioLabs.
Smarty is an old and tenacious template engine. To be honest, I don't like it very much. Its syntax is too complicated, and things like variable assignment have their own set of methods. The current version uses Lexer to parse files, which feels like another language implemented in PHP. There are also some regular expressions that are too long and implementations that are too complex in the project. I think this is a very dangerous and error-prone thing.

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is a server-side scripting language that is used to develop dynamic websites, web applications, and web programs. PHP has a wide range of applications, and both beginners and experienced developers can benefit from it. This article will provide you with an introductory guide to the basic syntax of PHP. If you want to learn PHP programming and build a solid foundation from scratch, you've come to the right place. The basic structure of PHP. A PHP program contains the following three parts: <?php//PHP code?>& on both sides of the code

In web development, file uploading and downloading is a very common requirement. Whether users upload avatars or documents, or administrators ask users to download a file, this function is needed. As a powerful server-side language, PHP naturally provides powerful file operation functions and class libraries, allowing us to easily implement file upload and download functions. This article will introduce the basic process and common functions to implement file upload and download in PHP, and provide sample code. If you are a PHP beginner or are learning file operations

As a popular server-side scripting language, PHP can be used not only for the development of Web applications, but also for TCP/IP programming and network programming. In this article, we will introduce you to the basics of TCP/IP programming and how to use PHP for TCP/IP programming. 1. Basic knowledge of TCP/IP programming TCP/IP protocol is the standard protocol for communication on the Internet. It is composed of two parts: TCP protocol and IP protocol. The TCP protocol is responsible for establishing reliable connections

As a front-end developer, understanding PHP is very necessary. Although PHP is a back-end development language, mastering a certain amount of PHP knowledge can help front-end developers better understand the entire web development process, improve work efficiency, and collaborate better with back-end developers. In this article, we will discuss some PHP-related knowledge that front-end developers need to know and provide specific code examples. What is PHP? PHP (HypertextPreprocessor) is a server

PHP is a popular front-end programming language. It is powerful, easy to learn and use, and is widely used in website development and maintenance. For beginners, getting started with PHP requires a certain amount of learning and mastering. Here are some guides for beginners in PHP. 1. Learn basic concepts Before learning PHP, you need to understand some basic concepts. PHP is a scripting language that issues instructions to web servers. Simply put, you can use PHP to generate HTML code and send it to the browser to eventually render on the web page

PHP is a widely used programming language, especially in web development, PHP occupies an important position. Among them, JSON is a common data format that can be used to store and transmit data. JSON extensions are provided in PHP to facilitate developers to operate and process JSON data. This article will introduce the basic usage and application scenarios of JSON extension. 1. Basic usage of JSON extension. Convert JSON string into PHP object or array. The json_decode() function in PHP can convert

For PHP beginners, it is very important to understand HTTP status codes. HTTP status code refers to the 3-digit code returned by the web server and is used to indicate the processing result of the client request. This article will introduce some common HTTP status codes and their meanings to help PHP beginners better understand the various HTTP status codes encountered during website development. 200OK200OK is one of the most common HTTP status codes, indicating that the request was successfully processed and a result was returned. When you visit a website, such as

PHP is a very popular programming language that is often used in the field of Internet development. In PHP development, cache settings are a very important part. Caching can improve website performance and user experience, reduce server load, and is one of the common methods for website optimization. This article will introduce you to the introductory guide to setting up PHP cache. 1. What is cache? Caching is to store some frequently accessed data in memory so that it can be quickly obtained the next time it is accessed, avoiding repeated calculations or database queries and improving response speed. PHP, slow
