Framework: Fresh install of laravel/laravel v6.5.2 fails: Return value of "...PackageDiscoverCommand::execute()" should always be of the type int

Created on 30 Nov 2019  路  14Comments  路  Source: laravel/framework

  • Laravel Version: 6.5.2
  • PHP Version: 7.3.11
  • Database Driver & Version: mysqlnd 5.0.12-dev

Description:

Calling composer create-project --no-cache laravel/laravel laravel fails after Package manifest generated successfully.with

ErrorException : Return value of "Illuminate\Foundation\Console\PackageDiscoverCommand::execute()" should always be of the type int since Symfony 4.4, NULL returned.

Steps To Reproduce:

  • Attempt a fresh install with composer create-project --no-cache laravel/laravel laravel

Most helpful comment

@muni2explore thank you so much :)

For me (PHP 7.4 via Homebrew), setting xdebug.scream=0 makes all the difference. Before with xdebug.scream=1, installation breaks off with ErrorException : Return value of .... Now, it finishes without an error.

All 14 comments

The cause of the problem seems to be that Symfony 4.4 expects PackageDiscoverCommand::handle() to return an int which it does not do:

int-expected

Adding a return 0 fixes the problem.

I worked around the problem by using a composer patch:

  • install cweagans/composer-patches:
    composer require cweagans/composer-patches
  • add the patch file as patches/PackageDiscoverCommand.patch
  • edit composer.json and add

"extra": { "patches": { "laravel/framework": { "PackageDiscoverCommand::execute() should return int": "patches/PackageDiscoverCommand.patch" } } },

  • call composer update and watch for this output:

````
Gathering patches for dependencies. This might take a minute.

  • Installing laravel/framework (v6.6.0): Loading from cache
  • Applying patches for laravel/framework
    patches/PackageDiscoverCommand.patch (PackageDiscoverCommand::execute() should return int)
    ````

Can you confirm your Laravel version, and the version of Symfony that is installed?

There is a change in Symfony 5 that console commands are now required to return ints, but I don't believe that applies to Symfony 4.4

https://github.com/laravel/framework/pull/30610#issuecomment-557746863

In Symfony 4.4 itself they are throwing deprecation Exception.

It is becuase Laravel and Lumen modules extend deprecated Symfony components.

Please check this comment
https://github.com/Codeception/Codeception/issues/5532#issuecomment-498158276.

Is there any work around for this deprecation Exception?

Because of Symfony 4.4 deprecation Exception not able to use Laravel v6.5.2.

Following Exception getting while expecting JSON response from API.

{
    "message": "The \"Symfony\\Component\\Debug\\Exception\\FatalThrowableError\" class is deprecated since Symfony 4.4.",
    "exception": "ErrorException",
    "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/symfony/debug/Exception/FatalThrowableError.php",
    "line": 14,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/symfony/debug/Exception/FatalThrowableError.php",
            "line": 14,
            "function": "trigger_error"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/composer/ClassLoader.php",
            "line": 444,
            "function": "include"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/composer/ClassLoader.php",
            "line": 322,
            "function": "Composer\\Autoload\\includeFile"
        },
        {
            "function": "loadClass",
            "class": "Composer\\Autoload\\ClassLoader",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 134,
            "function": "spl_autoload_call"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/barryvdh/laravel-cors/src/HandleCors.php",
            "line": 36,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Barryvdh\\Cors\\HandleCors",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 59,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 694,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 669,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 635,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 624,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 176,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 62,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/barryvdh/laravel-cors/src/HandlePreflight.php",
            "line": 29,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Barryvdh\\Cors\\HandlePreflight",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 151,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 116,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/Users/mayothi/www/chikku-sites/chikku-api/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}

Please check this comment https://github.com/Codeception/Codeception/issues/5532#issuecomment-498158276

composer create-project --no-cache laravel/laravel laravel

I can run this command just fine without errors.

It is the last step that fails:

php artisan package:discover --verbose

`
Package manifest generated successfully.

ErrorException : Return value of "IlluminateFoundationConsolePackageDiscoverCommand::execute()" should always be of the type int since Symfony 4.4, NULL returned.

at /Users/schettlero/work/links/vendor/symfony/console/Command/Command.php:258
254| } else {
255| $statusCode = $this->execute($input, $output);
256|
257| if (!is_int($statusCode)) {

258| @trigger_error(sprintf('Return value of "%s::execute()" should always be of the type int since Symfony 4.4, %s returned.', get_class($this), gettype($statusCode)), E_USER_DEPRECATED);
259| }
260| }
261|
262| return is_numeric($statusCode) ? (int) $statusCode : 0;

Exception trace:

1 trigger_error("Return value of "IlluminateFoundationConsolePackageDiscoverCommand::execute()" should always be of the type int since Symfony 4.4, NULL returned.")
/Users/schettlero/work/links/vendor/symfony/console/Command/Command.php:258
`

This happens on a Mac with PHP 7.3.11. Sadly, on an Ubuntu-Box with PHP 7.2.10, the very same command works just fine. I guess there is some PHP setting that makes the ErrorException dump on the Mac. But which one?

if (!\is_int($statusCode)) {
    @trigger_error(sprintf('Return value of "%s::execute()" should always be of the type int since Symfony 4.4, %s returned.', \get_class($this), \gettype($statusCode)), E_USER_DEPRECATED);
}

this is the important code. what it's saying is if the $statusCode is not an integer, throw a deprecation notice. However, it also suppresses the error with the leading @ symbol.

The differences in your system probably have to do with the level of error/warning/notices that you have turned on.

By running the command with the --verbose flag, you are probably also forcing it into "debug" mode, so it is displaying warnings like this to you. Drop this flag, and I would guess that fixes it.

I made a simple test between my Mac (where I get the deprecation message) and an Ubuntu box where I don't get the message.

Here is the code:

<?php echo phpversion(), ". Before ...\n"; @trigger_error("Something is deprecated", E_USER_DEPRECATED); echo "... after\n";

On the Mac, I get:

7.3.11. Before ... PHP Deprecated: Something is deprecated in /Users/schettlero/work/deprecated/check.php on line 3 PHP Stack trace: PHP 1. {main}() /Users/schettlero/work/deprecated/check.php:0 PHP 2. trigger_error() /Users/schettlero/work/deprecated/check.php:3 ... after

On Ubuntu, I get

7.2.10-0ubuntu0.18.04.1. Before ... ... after

So, the good news is that the echo with "...after" runs on both machines. However, except for the different PHP versions, checking with php -i I don't see a difference in the various settings for error logging between the two.

Just running composer create-project --no-cache laravel/laravel laravel
I still get

Exception trace:
  1   trigger_error("Return value of "Illuminate\Foundation\Console\PackageDiscoverCommand::execute()" should always be of the type int since Symfony 4.4, NULL returned.")
      C:\Users\bongo\Documents\Secondary_Workspace\lighthouse-custom\vendor\symfony\console\Command\Command.php:258

  2   Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      C:\Users\bongo\Documents\Secondary_Workspace\lighthouse-custom\vendor\laravel\framework\src\Illuminate\Console\Command.php:189

When the install is finishing.

composer create-project --no-cache laravel/laravel laravel

this issue is still exists in Mac OS. It is working fine in Ubuntu

PHP Version 7.2

Please reopen the issue.

I found root cause of the issue. php error suppression operator (@) not working.

This is because of scream.enabled=1 in your php.ini config. Please disable that. For details refer the following link.

https://forum.smarttutorials.net/2019/12/errorexception-return-value-of.html

@proxyfoxwork @oschettler @driesvints @browner12

@muni2explore I can install laravel just fine with that command. The only problem I see is that you're probably having issues with the latest changes in Symfony 5 (which won't be supported until Laravel 7).

@muni2explore thank you so much :)

For me (PHP 7.4 via Homebrew), setting xdebug.scream=0 makes all the difference. Before with xdebug.scream=1, installation breaks off with ErrorException : Return value of .... Now, it finishes without an error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzp819739483 picture lzp819739483  路  3Comments

YannPl picture YannPl  路  3Comments

progmars picture progmars  路  3Comments

JamborJan picture JamborJan  路  3Comments

kerbylav picture kerbylav  路  3Comments