Install PHPColor

Install PHPColor and verify that Composer loads it correctly.

Requirements

PHPColor requires PHP 8.3 or later. It has no runtime package dependencies beyond PHP itself, but Composer is the supported installation path.

Check the PHP version used by your command line:

php --version
php --version

If the reported version is earlier than 8.3, select or install a compatible PHP runtime before requiring the package.

Install with Composer

From your project directory, run:

composer require phpcolor/phpcolor
composer require phpcolor/phpcolor

Composer adds PHPColor to your project and generates or updates vendor/autoload.php.

Verify the installation

Create verify-phpcolor.php in the project directory:

<?php

require __DIR__.'/vendor/autoload.php';

use PhpColor\Color\Color;

$color = Color::parse('#336699');

echo $color->toHex().PHP_EOL;
<?php require __DIR__.'/vendor/autoload.php'; use PhpColor\Color\Color; $color = Color::parse('#336699'); echo $color->toHex().PHP_EOL;

Run it with the same PHP executable you intend to use for the project:

php verify-phpcolor.php
php verify-phpcolor.php

The expected output is:

#336699
#336699

This verifies Composer autoloading, the PhpColor\Color namespace, parsing, and hexadecimal formatting in one small check.

Troubleshooting

Composer rejects the PHP version

Symptom: composer require fails with a message citing phpcolor/phpcolor and php >=8.3.

Fix: Composer uses the PHP binary that runs it, which can differ from your shell's php. Compare the two:

php --versioncomposer --version
php --version composer --version

composer --version prints the PHP version Composer runs on. If it is older than 8.3, invoke Composer with the right runtime, or update the runtime it finds first on your PATH.

Color class not found

Symptom: the verification script fails with Class "PhpColor\Color\Color" not found.

Fix: the require line must point at the vendor/autoload.php of the project where you ran composer require. Check the relative path from the script to vendor/, then regenerate the autoloader if needed:

composer dump-autoload
composer dump-autoload

PHPColor is installed and autoloading. Time to make some colors.