官方庫地址:https://packagist.org/packages/endroid/qr-codephp
PHP5.6 的最高版本爲:2.5.1json
經過composer安裝composer
composer require endroid/qr-code 2.5.1
安裝結果ui
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 8 installs, 0 updates, 0 removals
- Installing myclabs/php-enum (1.7.2): Downloading (100%)
- Installing symfony/polyfill-ctype (v1.12.0): Downloading (100%)
- Installing symfony/property-access (v2.8.50): Downloading (100%)
- Installing bacon/bacon-qr-code (1.0.3): Downloading (100%)
- Installing symfony/options-resolver (v2.8.50): Downloading (100%)
- Installing endroid/qr-code (2.5.1): Downloading (100%)
- Installing topthink/framework (v5.1.38.1): Downloading (100%)
bacon/bacon-qr-code suggests installing ext-gd (to generate QR code images)
使用spa
use Endroid\QrCode\QrCode;
$qrCode = new QrCode('Life is too short to be generating QR codes');
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
出錯了code
syntax error, unexpected ':', expecting ';' or ' php-enum/src/Enum.php:88
語法解析錯誤呀。應該是PHP7的三元運算符搞得鬼orm
也就是這個依賴庫版本的問題:symfony
myclabs/php-enum (1.7.2): Downloading (100%)
查看該依賴庫須要的PHP版本blog
能夠很清楚的看到,安裝endroid/qr-code庫使用默認安裝的依賴庫包都是最新的,須要PHP7的ci
如何解決問題?
從新找一個myclabs/php-enum安裝包使用於PHP5.6的
指定版本安裝
composer require myclabs/php-enum 1.6.6
再次生產二維碼,成功了。
小結:針對PHP5.6版本使用 endroid/qr-code 二維碼庫,須要在composer.json文件中添加包
"endroid/qr-code": "2.5.1",
"myclabs/php-enum": "1.6.6"
其實在解決問題以前,我總覺得版本過高的問題,甚至把endroid/qr-code 的版本都搞到1.9 去了
沒有解決問題啊