Difference between require-dev and require in PHP?

Before going to understand the difference between require and require_dev first understand what is require and require_dev.

require: These are must packages for the code to run. It defines the actual dependency as well as package version.
require_dev: It defines the packages necessary for developing the project and not needed in production environment.

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

What is composer?
Composer is dependency/parameter manager in php. It can be used to install keep a track of and update project dependency. Composer also takes care of autoload of dependencies that application relies on letting easily use the dependency inside the project without worrying about including them at the top of any given file. Dependency for project are listed within a “composer.json” file which typically located in the project root. This file holds the information about required version of packages for production and development. This file can be edited manually using any text editor or automatically through the command line via command such as “composer require ” or “composer require_dev .
To start using composer in the project first need to create composer.json file. It can be either created manually or simply run composer init. After run composer init in the terminal it will ask some basic information about the project such as package name, description (it is optional), Author and source other information like minimum stability, license and required package.
The require key in the composer.json specifies composers which packages the project depends on require takes an object that maps package names

    "require": {
        // name of package.
        "composer/composer:" "1.2.*"

In the above example “composer/composer” specifies vendor name and project name separated by slash (‘/’) and “1.2.*” specifies the version name.
To install the dependency need to run the composer install command and then it will find the defined package that method for supplied version constraints and download it into vendor directory. It convention to put third party code into directory named vendor. The installed command also created a composer.lock file.

Difference Between require and require_dev:

  • require:
    • It define actual dependency as well as package version.
    • The require lists the package require by this package.
    • The package will not be installed unless those requirements can be met.
  • require_dev:
    • It define the packages necessary for developing project.
    • The require_dev lists packages required for developing this package, or running tests, etc.
    • The dev requirements of the root package are installed by default. Both install or update support the “–no-dev” option that prevents dev dependencies from being installed.

This article is attributed to GeeksforGeeks.org

leave a comment



load comments

Subscribe to Our Newsletter