Home  >  Article  >  Backend Development  >  Difference between require-dev and require in PHP

Difference between require-dev and require in PHP

藏色散人
藏色散人Original
2019-02-20 10:04:596145browse

Before understanding the difference between require and require_dev, you must first understand what require and require_dev are.

Difference between require-dev and require in PHP

require: These are the necessary packages to run the code. It defines the actual dependencies as well as package versions.

require_dev: It defines the packages required for the development project, not the packages required in the production environment.

Note: require and require_dev are important parameters available in composer.json.

What is Composer?

Composer is a dependency/parameter manager in php. It can be used for installation tracking and updating project dependencies. Composer also handles the automatic loading of dependencies, and applications that rely on them can easily use the dependencies in your project without having to worry about including them at the top of any given file. A project's dependencies are listed in the "composer.json" file, which is typically located in the project root directory.

This file contains information about the package versions required for production and development. This file can be edited manually using any text editor or automatically via the command line such as "composer require" or "composer require_dev".

To start using composer in your project, you first need to create the composer.json file. It can either be created manually or just run composer init. After running composer init in terminal, it will ask for some basic information about the project such as package name, description (optional), author and source and other information such as minimum stability, license and required packages.

The require key in composer.json specifies the combinator containing the project that depends on require, which requires an object mapping the package name

Example:

{ 
    "require": { 
  
        // 包的名称
        "composer/composer:" "1.2.*"
    } 
}

In the above example , "composer/composer" specifies the vendor name and project name separated by a slash ('/'), and "1.2.*" specifies the version name.

To install dependencies you need to run the composer install command, then it will find the defined package for the provided version constraints and download it into the vendor directory. It places third-party code into a directory called vendor. The installation command also creates a composer.lock file.

Difference between require and require_dev:

require:

It defines the actual dependencies as well as the package version .

require lists the packages required by this package.

The package will not be installed unless these requirements are met.

require_dev:

It defines the packages required to develop the project.

require_dev lists the packages required to develop this package or run tests etc.

The dev requirements of the root package will be installed by default. Either install or update supports the "-no-dev" option to prevent dev dependencies from being installed.

Related recommendations: "PHP Tutorial"http://www.php.cn/course/list/29.html

The above is the detailed content of Difference between require-dev and require in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn