Difference between require-dev and require in PHP? - GeeksforGeeks

05 Nov, 2018
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 namesExample:
{    "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.
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.
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.
PHP-packages
Picked
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to convert array to string in PHP ?
PHP | Converting string to Date and DateTime
How to pass JavaScript variables to PHP ?
How to fetch data from localserver database and display on HTML table using PHP ?
How to run JavaScript from PHP?
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?