23

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 '{'

Please assist

Thanks in advance

Using Laravel Framework version 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

public static function tableize(string $word) : string
    {
        return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
    }
Abdul Qadir R.
  • 1,059
  • 3
  • 9
  • 26

7 Answers7

61

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.

But if you want to stay at your current PHP version, you can downgrade the doctrine/inflector version by running the following commands:

  1. Delete the composer.lock file

    rm -f Composer.lock

  2. Delete the vendor

    rm -R -f vendor

  3. composer install

  4. Install the doctrine/inflector according to your php version

    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

Yogesh Nogia
  • 1,026
  • 9
  • 12
  • 1
    How to change php version: https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04 – nwolybug Apr 10 '18 at 15:52
  • Thank you very much. I ran into similar issues while using Laravel 5.0 on PHP version 5.6. This did the trick. – Fran Cano Mar 01 '19 at 11:27
5

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.

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.

You are using PHP 5.6.24, so this code won't work on your system.

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.*.

Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • That doesn't work for me. I have a Laravel 5 app running on PHP 5.6. Composer requires laravelcollective/html version 5.0. Inflector for version 5.0 does not work on PHP 5.6. But Laravel 5.0's error handling doesn't work on PHP 7.0. A complete catch 22. – MrMoxy Apr 03 '19 at 02:39
5

I'm working on:

  • Laravel 5.1
  • PHP 5.6.36

My table name is like this: "test_meetings"

I solved the error specifying in testMeeting.php Model the table name:

protected $table = 'test_meetings';
Alessandro
  • 409
  • 5
  • 12
1

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.

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)

This cleared up the issues.

cw24
  • 1,613
  • 2
  • 22
  • 31
1

Delete composer.lock file

`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 require doctrine/inflector:1.2.0 (this will work with 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.*
Umar Tariq
  • 1,191
  • 1
  • 13
  • 14
  • inflector:1.2.0 also works with php 7.2. In my case downgrade inflector from 1.4.3 to 1.2.0 solved the problem. – MrMojoRisin Aug 14 '20 at 01:01
0

after

composer install

Try this after you have run the composer update:

php artisan cache:clear
0

I solved my problem by explicitly giving table name in model protected $table = 'table_name';