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.
Run either composer create-project laravel/laravel or composer update on an existing project.
Thanks in advance!
https://github.com/briannesbitt/Carbon/issues/1250#issuecomment-381591572
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.
Thanks for the feedback, we will try to find out why this happens and release a fix on Carbon.
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.
@kylekatarnls I havn't tried, but this looks to be a conflict in Laravel's own Carbon class. Make sure you're using IlluminateSupportCarbon if you're attempting to reproduce the problem.
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).
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
Carbon just released a new version(a few hours ago) that adds macros and mixins, which conflicts with IlluminateSupportCarbon via a trait.
Sorry miss-typed, it's Carbon 1.26, the file contains protected static $macros = array();
@devcircus 1.26.1 renamed the variable, you can update.
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();
1.26.2 seems to have fixed the issue.
Glad to hear, because I still not was able to reproduce even by trying maximal error_reporting level. Now that Carbon added IlliminateSupportCarbon 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.
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].
@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 IlluminateSupportCarbon (#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.
Most helpful comment
@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 IlluminateSupportCarbon (#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.