I am working on a project for a WebApp and I would like to specify types for my class properties. I didn't realise this is a PHP version 7.4.* feature, so I read this and updated my composer.json
to include the relevant material:
{
"name": "srmes/shopping-app-test",
"description": "an assignment from `scandiweb.com`. A simple php-based web application to display and inventory a range of products",
"require-dev": {
"phpunit/phpunit":"~9.0",
"squizlabs/php_codesniffer": "~3.0"
},
"require": {
"doctrine/orm": "~2.7",
"php": "7.4.4"
},
"config": {
"platform": {
"php": "7.4.4"
}
},
"autoload" : {
"psr-4": {
"WebApp\\": "src/"
}
},
"autoload-dev" : {
"psr-4": {
"WebApp\\Tests\\" : "tests/"
}
}
}
I then ran composer install
and composer update
.
No problems seemed to occur with the install, except that now my phpunit tests don't run:
PHPUnit 9.1.1 by Sebastian Bergmann and contributors.
Time: 58 ms, Memory: 4.00 MB
No tests executed!
And all composer
commands give the following error:
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /Users/ScottAnderson/Documents/Tech/commissions/shopping_app_test/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 33
Ironically this is syntax exception about the php feature I was trying to utilise! I can't even run composer -vvv
to debug which php executable is being used by composer.
In order to resolve this should I use a package like phpbrew to make directory environments of php?
My assumption was that after requiring php 7.4.4 in composer.json
that the correct php executable would be installed and used by composer and phpunit
Looks like you are not running php 7.4. and the dependencies installed (here phpunit and PackageVersion) need it. Sometimes composer runs commands hooked on events and if the command fails everything else can fall.
Btw composer manages project dependencies, not php versions installed. If you're starting out in PHP I'd recommend to stick with 7.3 which is widely available. Honestly you don't need the latest syntax additions to the language.