Now write PHP, you should know these _ PHP tutorials

Source: Internet
Author: User
Tags coding standards php coding standards codeigniter ruby on rails
Now you should know about PHP. Now, if you write PHP, you should know that you are using PHP5.3 or later. if the PHP version is below, it is time to upgrade. I suggest you use PHP now if you have the necessary conditions.

First, you should be using PHP 5.3 or above. if the PHP version is below, it is time to upgrade. I recommend that you use the latest version if necessary.

You should have read PHP The Right Way. This article contains a lot of content and can be expanded. You need to understand most 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 PSRPHP Standard Recommendation many times in my previous articles and my colleagues ). Many people think that this is only a matter of standardizing the code style, but it is far more than that.

A series of standard documents of this report are drafted and voted on by php-fig (PHP Framework Interop Group). the voting members include authors of mainstream frameworks and extensions, including Laravel, Symfony, and Yii.

According to the official website, the purpose of this organization is not to tell you how to do it, but to negotiate and agree between some mainstream frameworks. But I believe that these frameworks and extensions will always be used by you.

A total of 6 documents are currently passed by the DSRs:

  • 0: automatic loading is mainly for versions without namespaces before PHP 5.3)

  • 1: Coding Specification

  • 2: recommended encoding styles

  • 3: Log results

  • 4: automatic loading is much more refined after the namespace is displayed)

  • 7: HTTP Message Interface

Currently in drafting Draft) there are PSR-5 (PHPDoc Standard), PSR-6 (Cache) and so on. 5 and 6 are not displayed in the above list because they have not passed the vote.

I believe that with the constant update of standards, you will find that studying these conventions is also very beneficial to you, although it may not always follow 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 to install extensions, but also defines a modern PHP framework implementation and extension management method. Similar to node. js npm, Python pip, but more than above.

The core of composer is to implement standard extension installation and automatic class loading. Through packagist.org, numerous extension components can be easily introduced. Currently, many well-known PHP extensions can be installed through composer. The call only requires loading 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 has also made an optimization.

We all know that the introduction of PHP files should be implemented through include and require, which is not very well written. PHP 5.3 provides namespaces, which are irrelevant to file introduction. But composer implements the PSR-4 in the old version of PHP is the PSR-0), using use by calling the spl_autoload_register method to load the required class when calling, similar to the import of Python in terms of writing, it is both beautiful and plays a role of loading on demand and delayed 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 role of this tool is to format your code according to PSR-1 and PSR-2 specifications, and there are some optional encoding styles that are Symfony specifications.

In fact, this is not so worth mentioning, but recently I have seen the. php_cs file in several open-source frameworks. I was curious to find this project.

Project address: https://github.com/FriendsOfPHP/PHP-CS-Fixer

The specific usage and configuration methods are described on the project homepage. The organization name is also interesting: FriendsOfPHP. The main member is probably from the Symfony project.

Some people may think that the tangle of code style is not necessary. If you think programming is more than just a job, it's just like packing up your room. the dirty room doesn't affect your meals and sleep, but the clean looks more comfortable. If you want to work with others, this is even more important.

4. PsySH

A runtime developer console, interactive debugger and REPL for PHP.

PsySH is similar to the Python IDLE's PHP interactive runtime environment. This is what I found in Laravel. Laravel 5's artisan tinker function is implemented through it. Laravel 4 uses another project: boris.

This is easy to use when testing some simple php functions and features. You can use empty for some uncertain tasks, such as the use of empty.

5. some frameworks and components

Framework

I prefer Laravel. Currently, the company is using Yii2. I am concerned with Symfony and Phalcon C language ). I don't need to use anything, but I like it. sometimes I can't choose it myself. but I have to study it for a better understanding.

Many people will immediately think of Ruby on Rails when talking about Laravel. I want to imitate or plagiarize this is not the main purpose, the main purpose is to provide developers with a better tool. Laravel has a different routing control without the Action suffix or prefix. it has a good ORM (Eloquent) and a good template engine (Blade) or if there is a document community with a relatively high profile value.

Sometimes it will be criticized for its strength, but it is because you need to understand the long-term planning of your project, the current size of the project, and the future size and bearing capacity.

Larval core implementation is a Container) and PHP Reflection class ReflectionClass) Yii 2 is the same ). To understand this, you can also look at the source code while reading articles and documents.

Symfony 2 provides many components. Http-kernel and http-foundation are also inherited and used directly in Laravel. It is worth understanding and learning.

CodeIgniter is a small and powerful framework. Although CI does not use the Composer component for development, but versions later than 3.0 have also added support for Composer. this is nothing more than a file that contains a vendor Directory and introduces autoload. php.

ORM

ORM or Active Record. Some people may think that PHP is a template engine and should write SQL. Do not be troubled by these words.

The implementation of Active Record in CodeIgniter is lightweight, but it is very useful for the CI itself.

I like the Eloquent implemented by Laravel. It can also be integrated into other projects. Symfony 2 uses Doctrine, which deserves attention. Yii 2 also has its own implementation method.

Template engine

The template engine needs to do three things:

The Blade implemented by Laravel is a lightweight and easy-to-use template engine. However, it is not very good to introduce it to other frameworks. During the 11th, I tried to introduce it to Yii 2. now it is just a simple implementation. I hope that the parsing part of Blade will be extracted separately for a lightweight implementation. I found someone doing the same thing on Github.

Yii 2 seems to recommend writing with native PHP, but it also provides support for extensions of Smarty and Twig. Symfony 2 uses Twig. Twig, Symfony, and the php-cs-fixer mentioned above are both SensioLabs works.

Smarty is an old and tenacious template engine. To be honest, I don't like it too much. Its syntax is too complicated. the assignment of variables has its own practice. In the current version, Lexer is used to parse files. it seems that PHP is used to implement another language. There are some too long regular expressions and complicated implementations in the project. I think this is a very dangerous and easy to make mistakes.

Ghost PHP, you should know that you should first use PHP 5.3 or later versions. if the PHP version is below, it is time to upgrade. I suggest you use it if you have conditions...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.