Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carbon 1.26.0 causes some trouble!? #23893

Closed
tobysommer opened this issue Apr 16, 2018 · 14 comments
Closed

Carbon 1.26.0 causes some trouble!? #23893

tobysommer opened this issue Apr 16, 2018 · 14 comments

Comments

@tobysommer
Copy link

  • Laravel Version: 5.6.16
  • PHP Version: 7.2

Description:

Creating a new Laravel project (composer create-project laravel/laravel) returns with the following error (the project is created though):

> @php artisan package:discover
PHP Fatal error:  Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed in /Users/tobias/Code/testCarbon/vendor/laravel/framework/src/Illuminate/Support/Carbon.php on line 9

   Symfony\Component\Debug\Exception\FatalErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at /Users/tobias/Code/testCarbon/vendor/laravel/framework/src/Illuminate/Support/Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**


   Whoops\Exception\ErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at /Users/tobias/Code/testCarbon/vendor/laravel/framework/src/Illuminate/Support/Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

This happens as soon as Carbon gets updated to v1.26.0. composer update is also affected.

Steps To Reproduce:

Run either composer create-project laravel/laravel or composer update on an existing project.

Thanks in advance!

@Miguel-Serejo
Copy link

briannesbitt/Carbon#1250 (comment)
https://laracasts.com/discuss/channels/laravel/php-fatal-error-carboncarbon-and-illuminatesupporttraitsmacroable
https://laracasts.com/discuss/channels/laravel/composer-update-broke-my-laravel-project?page=1

composer require nesbot/carbon 1.25.* should fix your project for now.
@taylorotwell already updated the framework's composer.json but has yet to tag a new release. This should be fixed soon.

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Apr 16, 2018

Thanks for the feedback, we will try to find out why this happens and release a fix on Carbon.

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Apr 16, 2018

I provided 1.26.1 using an other name, but I still cannot reproduce this error, I use PHP 7.2, create a new 5.6.16 project, it install Carbon 1.26.0 with no problem. If someone know why it not always happen, I'm interested.

@sisve
Copy link
Contributor

sisve commented Apr 16, 2018

@kylekatarnls I havn't tried, but this looks to be a conflict in Laravel's own Carbon class. Make sure you're using Illuminate\Support\Carbon if you're attempting to reproduce the problem.

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Apr 16, 2018

I do:

use Illuminate\Support\Carbon;

class SomeMiddleware
{
    public function handle($request, Closure $next)
    {
        Carbon::macro('test', function () {
            return 'test';
        });
        $d = new Carbon();
        echo $d->test();
        exit;
    }
}

This display "test". PHP 7.2.3, Laravel 5.6.16, Carbon 1.26.0 (Windows 10).

@Miguel-Serejo
Copy link

Miguel-Serejo commented Apr 16, 2018

This display "test". PHP 7.2.3, Laravel 5.6.16, Carbon 1.25.0 (Windows 10).

The issue is with Carbon 1.26

After creating a new project (composer create-project laravel/laravel) and pulling in the latest 1.26.1 Carbon tag:

> @php artisan package:discover
PHP Fatal error:  Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed in D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php on line 9

   Symfony\Component\Debug\Exception\FatalErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**


   Whoops\Exception\ErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

@devcircus
Copy link
Contributor

devcircus commented Apr 16, 2018

Carbon just released a new version(a few hours ago) that adds macros and mixins, which conflicts with Illuminate\Support\Carbon via a trait.

@kylekatarnls
Copy link
Contributor

Sorry miss-typed, it's Carbon 1.26, the file contains protected static $macros = array();

@kylekatarnls
Copy link
Contributor

@devcircus 1.26.1 renamed the variable, you can update.

@Miguel-Serejo
Copy link

Are you sure about 1.26.1?

D:\projects\laravel>composer info nesbot/carbon
name     : nesbot/carbon
descrip. : A simple API extension for DateTime.
keywords : date, datetime, time
versions : * 1.26.1
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source   : [git] https://github.com/briannesbitt/Carbon.git bab61b25da5a28a6a7a5785d34802174b2a24b99
dist     : [zip] https://api.github.com/repos/briannesbitt/Carbon/zipball/bab61b25da5a28a6a7a5785d34802174b2a24b99 bab61b25da5a28a6a7a5785d34802174b2a24b99
names    : nesbot/carbon

autoload
psr-4
* => src/

requires
php >=5.3.9
symfony/translation ~2.6 || ~3.0 || ~4.0

requires (dev)
friendsofphp/php-cs-fixer ~2
phpunit/phpunit ^4.8.35 || ^5.7

D:\projects\laravel>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

   Symfony\Component\Debug\Exception\FatalErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**


   Whoops\Exception\ErrorException  : Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed

  at D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php:9
     5| use JsonSerializable;
     6| use Carbon\Carbon as BaseCarbon;
     7| use Illuminate\Support\Traits\Macroable;
     8|
  >  9| class Carbon extends BaseCarbon implements JsonSerializable
    10| {
    11|     use Macroable;
    12|
    13|     /**

PHP Fatal error:  Carbon\Carbon and Illuminate\Support\Traits\Macroable define the same property ($macros) in the composition of Illuminate\Support\Carbon. However, the definition differs and is considered incompatible. Class was composed in D:\projects\laravel\vendor\laravel\framework\src\Illuminate\Support\Carbon.php on line 9
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Checking the actual file, the variable is still named $macros (lines 243-248)

    /**
     * The registered string macros.
     *
     * @var array
     */
    protected static $macros = array();

@Miguel-Serejo
Copy link

1.26.2 seems to have fixed the issue.

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Apr 16, 2018

Glad to hear, because I still not was able to reproduce even by trying maximal error_reporting level. Now that Carbon added Illiminate\Support\Carbon features, we'll be able to remove Laravel overrides and it would be the end of compatibility problems and gap between Carbon and Laravel's Carbon.

@nbolender
Copy link

Hope that Laravel will once again adopt the latest Carbon version because some very handy functionality has been added in 1.26. For now I'm locking my project to laravel/[email protected] and nesbot/[email protected].

@kylekatarnls
Copy link
Contributor

@nbolender Not sure they will come to read closed issues. I regret this situation but it's needed to take the time to think about what to keep/remove Laravel side in Illuminate\Support\Carbon (#23938, #23941) to upgrade it the right way.

As a temporary fix, you can also use in your composer.json "nesbot/carbon": "1.27.0 as 1.25.0".

Not ideal since you need to upgrade manually carbon, but it allow you to keep the laravel/[email protected].* dependency up to date and having up to date carbon too with no conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants