You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Classes that extend Carbon like jensseggers/date or this one have one major inconvenient. You have to choose one or the other. You can't benefit of both methods of 2 or more classes that extend a first one (Carbon in this case).
A more extensible approach is to use traits and Carbon provides out of the box the mixin() method which can take as much traits as you want as long as they don't use the same methods names:
And this is a backward-compatible change as you can do:
<?phpnamespaceLee;
useCarbon\Carbon;
// Optionally you can deprecate it for next version
@trigger_error('CarbonExtended class is deprecated and will be removed in carbon-extended 2, use Carbon::mixin(CarbonExtendedTrait::class) instead.', E_USER_DEPRECATED);
class CarbonExtended extends Carbon
{
use CarbonExtendedTrait;
}
And Carbon documentation has a macro section where such mixins/macros can be promoted if you want by submitting a pull-request on gh-pages branch on https://github.com/briannesbitt/Carbon
The text was updated successfully, but these errors were encountered:
Hello,
Classes that extend Carbon like jensseggers/date or this one have one major inconvenient. You have to choose one or the other. You can't benefit of both methods of 2 or more classes that extend a first one (Carbon in this case).
A more extensible approach is to use traits and Carbon provides out of the box the
mixin()
method which can take as much traits as you want as long as they don't use the same methods names:Try on try-carbon.herokuapp.com
And this is a backward-compatible change as you can do:
And Carbon documentation has a macro section where such mixins/macros can be promoted if you want by submitting a pull-request on gh-pages branch on https://github.com/briannesbitt/Carbon
The text was updated successfully, but these errors were encountered: