Explain how Composer ensures consistent project dependencies across different environments and how to safely update them. Specifically, describe the purpose of `composer.json` and `composer.lock` files, how `composer install` and `composer update` commands are used, and best practices for committing these files to version control.
Navigate to the 'Basic usage' documentation page on getcomposer.org. Locate and read the sections explaining `composer.json` and its purpose. Locate and read the sections explaining `composer.lock` and its purpose, particularly in relation to reproducible builds. Locate and read the sections explaining the `composer install` command and its interaction with `composer.lock`. Locate and read the sections explaining the `composer update` command and its interaction with `composer.json` and `composer.lock`. Identify the best practices for committing `composer.json` and `composer.lock` to version control. Synthesize the gathered information to explain the roles of the files and commands, and the version control best practices.
Clearly explain that `composer.json` defines project dependencies with version constraints. Clearly explain that `composer.lock` records exact dependency versions for reproducible builds across environments. Explain that `composer install` uses `composer.lock` (if present) for exact versions, or `composer.json` if `composer.lock` is absent. Explain that `composer update` resolves latest compatible versions from `composer.json` and updates `composer.lock`. State that `composer.lock` should be committed to version control to ensure consistent dependency versions. State that `composer.json` should also be committed to version control as it defines the project's dependencies.