Inflector.php 第 265 行中的 FatalErrorException:语法错误,意外的 ':',期待 ';' 或者 '{'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48380892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FatalErrorException in Inflector.php line 265: syntax error, unexpected ':', expecting ';' or '{'
提问by Abdul Qadir
I went to update composer using
我去更新作曲家使用
composer update
after update having the following error:
更新后出现以下错误:
FatalErrorException in Inflector.php line 265: syntax error, unexpected ':', expecting ';' or '{'
Inflector.php 第 265 行中的 FatalErrorException:语法错误,意外的 ':',期待 ';' 或者 '{'
Please assist
请协助
Thanks in advance
提前致谢
Using Laravel Framework version 5.2.45
使用 Laravel 框架版本 5.2.45
here is the composer code
这是作曲家代码
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "*.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/"
},
"files": [
"app/Libraries/Functions.php"
]
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
Please see the function of inflector.php where error occures
请查看inflector.php 出现错误的函数
public static function tableize(string $word) : string
{
return strtolower(preg_replace('~(?<=\w)([A-Z])~', '_', $word));
}
回答by Yogesh Nogia
It's a PHP version issue, update to PHP 7.0 and doctrine/inflector will work properly because doctrine/inflector 1.20 and above require PHP 7.
这是一个 PHP 版本问题,更新到 PHP 7.0 并且学说/inflector 将正常工作,因为学说/inflector 1.20 及更高版本需要 PHP 7。
But if you want to stay at your current PHP version, you can downgrade the doctrine/inflector version by running the following commands:
但是如果你想保持当前的 PHP 版本,你可以通过运行以下命令来降级学说/inflector 版本:
Delete the composer.lock file
rm -f Composer.lock
Delete the vendor
rm -R -f vendor
composer install
Install the doctrine/inflector according to your php version
composer require doctrine/inflector:1.1.0
删除 composer.lock 文件
rm -f Composer.lock
删除供应商
rm -R -f vendor
composer install
根据你的 php 版本安装学说/inflector
composer require doctrine/inflector:1.1.0
doctrine/inflector:1.1.0 supports PHP 5.6 & above. If you have another version of php, you can refer to this link
学说/inflector:1.1.0 支持 PHP 5.6 及更高版本。如果你有其他版本的php,可以参考这个链接
回答by Jerodev
It's really obvious when you search for this file name and then start comparing package versions.
当您搜索此文件名然后开始比较软件包版本时,这真的很明显。
You are requiring laravelcollective/html
at any version, so, for now, the latest version is 5.5.x
. This package in its turn requires "doctrine/inflector": "~1.1",
, so any version below 2.0
, which is currently 1.3.0
and requires PHP 7.0 or higher.
您需要laravelcollective/html
任何版本,因此,就目前而言,最新版本是5.5.x
. 这个包反过来需要"doctrine/inflector": "~1.1",
,所以下面的任何版本2.0
,目前1.3.0
需要 PHP 7.0 或更高版本。
If you look at the source of the latest inflector.php
, you will see a return type is set on line 265, which is only supported in PHP 7.0 and up.
如果查看最新的源代码inflector.php
,您会看到第 265 行设置了返回类型,仅 PHP 7.0 及更高版本支持。
You are using PHP 5.6.24, so this code won't work on your system.
您使用的是 PHP 5.6.24,因此此代码无法在您的系统上运行。
The simple way to fix your error is to use the laravelcollective/html
version corresponding to your Laravel version. Which should probably be 5.2.*
.
修复错误的简单方法是使用laravelcollective/html
与您的 Laravel 版本相对应的版本。这应该是5.2.*
。
回答by Alessandro
I'm working on:
我正在尝试:
- Laravel 5.1
- PHP 5.6.36
- Laravel 5.1
- PHP 5.6.36
My table name is like this: "test_meetings"
我的表名是这样的:“test_meetings”
I solved the error specifying in testMeeting.php Model the table name:
我解决了在 testMeeting.php 模型中指定表名的错误:
protected $table = 'test_meetings';
回答by cw24
In case this helps anyone. I had a similar problem. My doctrine/inflector was expecting php>=7 for some reason (That's what was to found in the composer.json from doctrine/inflector). And this even though I had followed the instructions to install laravel 5.4.
万一这对任何人都有帮助。我有一个类似的问题。由于某种原因,我的学说/inflector 期望 php>=7 (这是在来自教义/inflector 的 composer.json 中找到的内容)。即使我按照说明安装了 laravel 5.4。
I ran rm -f Composer.lock
and rm -R -f vendor
and then did a composer install
after vagrant ssh
to the homestead VM, which was using php 5.6.8 (originally I had run composer from my MacBook terminal, which was using php 7)
我跑rm -f Composer.lock
和rm -R -f vendor
,然后做了composer install
之后vagrant ssh
,以宅基地VM,它采用的是PHP 5.6.8(我原本运行作曲家从我的MacBook终端,它采用的是PHP 7)
This cleared up the issues.
这澄清了问题。
回答by mohamed elshazly
after
后
composer install
Try this after you have run the composer update:
运行 Composer 更新后试试这个:
php artisan cache:clear
回答by Umar Tariq
Delete composer.lock file
删除 composer.lock 文件
`rm -f Composer.lock`
Delete the vendor folder
删除供应商文件夹
rm -R -f vendor
composer install
作曲家安装
Then you can install a specific version of doctrine/inflector using composer for example:
然后你可以使用 composer 安装特定版本的学说/inflector,例如:
composer require doctrine/inflector:1.2.0
(this will work with php 7.0)
composer require doctrine/inflector:1.2.0
(这将适用于 php 7.0)
Also, it helps me to resolve the build issue to upgrade carbon if you are using
此外,如果您正在使用,它可以帮助我解决构建问题以升级碳
composer require nesbot/carbon=1.29.*