briannesbitt / Carbon

A simple PHP API extension for DateTime.
https://carbon.nesbot.com/
MIT License
16.57k stars 1.28k forks source link

Problem under laravel 7 #2067

Closed b-cil closed 4 years ago

b-cil commented 4 years ago

Hi there,

I have upgrade all my app to laravel 7 but when running following code $hist->created_at->diffForHumans()

I have the following error : Argument 1 passed to Carbon\CarbonInterval::setLocalTranslator() must implement interface Symfony\Component\Translation\TranslatorInterface, instance of Carbon\Translator given, called in /var/www/plateforme/vendor/nesbot/carbon/src/Carbon/Traits/Difference.php on line 778

As suggested by laravel I have modified the model : protected function serializeDate(DateTimeInterface $date){ return $date->format('Y-m-d H:i:s'); }

Please help me !

b-cil commented 4 years ago

I have been looking at following issue which is basically the same but don't see any solutions to resolve :

1941

my config php 7.4.4

adyen/php-api-library 6.1.0 A PHP client library for accessing Adyen APIs barryvdh/laravel-dompdf v0.8.6 A DOMPDF Wrapper for Laravel brick/math 0.8.15 Arbitrary-precision arithmetic library defuse/php-encryption v2.2.1 Secure PHP Encryption Library dnoegel/php-xdg-base-dir v0.1.1 implementation of xdg base directory specification for php doctrine/cache 1.10.0 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache,... doctrine/dbal v2.10.1 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management. doctrine/event-manager 1.1.0 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects. doctrine/inflector 1.3.1 Common String Manipulations with regard to casing and singular/plural rules. doctrine/instantiator 1.3.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 1.2.0 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. dompdf/dompdf v0.8.5 DOMPDF is a CSS 2.1 compliant HTML to PDF converter dragonmantank/cron-expression v2.3.0 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due egulias/email-validator 2.1.17 A library for validating emails against several RFCs elasticsearch/elasticsearch v7.6.1 PHP Client for Elasticsearch ezimuel/guzzlestreams 3.0.1 Fork of guzzle/streams (abandoned) to be used with elasticsearch-php ezimuel/ringphp 1.1.2 Fork of guzzle/RingPHP (abandoned) to be used with elasticsearch-php facade/ignition-contracts 1.0.0 Solution contracts for Ignition fideloper/proxy 4.3.0 Set trusted proxies for Laravel filp/whoops 2.7.1 php error handling for cool kids firebase/php-jwt v5.2.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. fzaninotto/faker v1.9.1 Faker is a PHP library that generates fake data for you. giggsey/libphonenumber-for-php 8.12.1 PHP Port of Google's libphonenumber giggsey/locale 1.8 Locale functions required by libphonenumber-for-php gocardless/gocardless-pro 3.6.2 GoCardless Pro PHP Client Library guzzlehttp/guzzle 6.5.3 Guzzle is a PHP HTTP client library guzzlehttp/promises v1.3.1 Guzzle promises library guzzlehttp/psr7 1.6.1 PSR-7 message implementation that also provides common utility methods hamcrest/hamcrest-php v2.0.0 This is the PHP port of Hamcrest Matchers intervention/validation 2.3.3 Additional Validator Functions for the Laravel Framework laminas/laminas-diactoros 2.2.3 PSR HTTP Message implementations laminas/laminas-zendframework-bridge 1.0.3 Alias legacy ZF class names to Laminas Project equivalents. laravel/framework v7.6.2 The Laravel Framework. laravel/passport v8.4.3 Laravel Passport provides OAuth2 server support to Laravel. laravel/tinker v2.4.0 Powerful REPL for the Laravel framework. laravel/ui v2.0.1 Laravel UI utilities and presets. lcobucci/jwt 3.3.1 A simple library to work with JSON Web Token and JSON Web Signature league/commonmark 1.3.4 Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and Github-Flavored Markdown (GFM) league/event 2.2.0 Event package league/flysystem 1.0.67 Filesystem abstraction: Many filesystems, one API. league/iso3166 2.1.5 ISO 3166-1 PHP Library league/oauth2-server 8.0.0 A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification... maatwebsite/excel 3.1.19 Supercharged Excel exports and imports in Laravel mangopay/php-sdk-v2 2.13.2 PHP SDK for MANGOPAY markbaker/complex 1.4.8 PHP Class for working with complex numbers markbaker/matrix 1.2.0 PHP Class for working with matrices mockery/mockery 1.3.1 Mockery is a simple yet flexible PHP mock object framework monolog/monolog 2.0.2 Sends your logs to files, sockets, inboxes, databases and various web services myclabs/deep-copy 1.9.5 Create deep copies (clones) of your objects nesbot/carbon 2.32.2 An API extension for DateTime that supports 281 different languages. nikic/php-parser v4.4.0 A PHP parser written in PHP nunomaduro/collision v4.2.0 Cli error handling for console/command-line PHP applications. nyholm/psr7 1.2.1 A fast PHP7 implementation of PSR-7 opis/closure 3.5.1 A library that can be used to serialize closures (anonymous functions) and arbitrary objects. paragonie/random_compat v9.99.99 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7 paragonie/sodium_compat v1.13.0 Pure PHP implementation of libsodium; uses the PHP extension if it exists phar-io/manifest 1.0.3 Component for reading phar.io manifest information from a PHP Archive (PHAR) phar-io/version 2.0.1 Library for handling version information and constraints phenx/php-font-lib 0.5.2 A library to read, parse, export and make subsets of different types of font files. phenx/php-svg-lib v0.3.3 A library to read, parse and export to PDF SVG files. php-http/message-factory v1.0.2 Factory interfaces for PSR-7 HTTP Message phpdocumentor/reflection-common 2.0.0 Common reflection classes used by phpdocumentor to reflect the code structure phpdocumentor/reflection-docblock 5.1.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is... phpdocumentor/type-resolver 1.1.0 A PSR-5 based resolver of Class names, Types and Structural Element Names phpoffice/phpspreadsheet 1.11.0 PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine phpoption/phpoption 1.7.3 Option Type for PHP phpseclib/phpseclib 2.0.27 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. phpspec/prophecy v1.10.3 Highly opinionated mocking framework for PHP 5.3+ phpunit/php-code-coverage 8.0.1 Library that provides collection, processing, and rendering functionality for PHP code coverage information. phpunit/php-file-iterator 3.0.1 FilterIterator implementation that filters files based on a list of suffixes. phpunit/php-invoker 3.0.0 Invoke callables with a timeout phpunit/php-text-template 2.0.0 Simple template engine. phpunit/php-timer 3.1.2 Utility class for timing phpunit/php-token-stream 4.0.0 Wrapper around PHP's tokenizer extension. phpunit/phpunit 9.1.1 The PHP Unit Testing framework. propaganistas/laravel-phone 4.2.3 Adds phone number functionality to Laravel and Lumen based on Google's libphonenumber API. psr/container 1.0.0 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.0.1 Common interface for HTTP messages psr/log 1.1.3 Common interface for logging libraries psr/simple-cache 1.0.1 Common interfaces for simple caching psy/psysh v0.10.3 An interactive shell for modern PHP. pusher/pusher-php-server dev-master e75e571 Library for interacting with the Pusher REST API ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. ramsey/collection 1.0.1 A PHP 7.2+ library for representing and manipulating collections. ramsey/uuid 4.0.1 A PHP library for generating and working with universally unique identifiers (UUIDs). react/promise v2.7.1 A lightweight implementation of CommonJS Promises/A for PHP sabberworm/php-css-parser 8.3.0 Parser for CSS Files written in PHP sebastian/code-unit 1.0.0 Collection of value objects that represent the PHP code units sebastian/code-unit-reverse-lookup 2.0.0 Looks up which function or method a line of code belongs to sebastian/comparator 4.0.0 Provides the functionality to compare PHP values for equality sebastian/diff 4.0.0 Diff implementation sebastian/environment 5.1.0 Provides functionality to handle HHVM/PHP environments sebastian/exporter 4.0.0 Provides the functionality to export PHP variables for visualization sebastian/global-state 4.0.0 Snapshotting of global state sebastian/object-enumerator 4.0.0 Traverses array structures and object graphs to enumerate all referenced objects sebastian/object-reflector 2.0.0 Allows reflection of object attributes, including inherited and non-public ones sebastian/recursion-context 4.0.0 Provides functionality to recursively process PHP variables sebastian/resource-operations 3.0.0 Provides a list of PHP built-in functions that operate on resources sebastian/type 2.0.0 Collection of value objects that represent the types of the PHP type system sebastian/version 3.0.0 Library that helps with managing the version number of Git-hosted PHP projects setasign/fpdf 1.8.2 FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any ... setasign/fpdi v2.3.2 FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as temp... spatie/laravel-honeypot 2.2.0 Preventing spam submitted through forms swiftmailer/swiftmailer v6.2.3 Swiftmailer, free feature-rich PHP mailer symfony/console v5.0.7 Symfony Console Component symfony/css-selector v5.0.7 Symfony CssSelector Component symfony/error-handler v5.0.7 Symfony ErrorHandler Component symfony/event-dispatcher v5.0.7 Symfony EventDispatcher Component symfony/event-dispatcher-contracts v2.0.1 Generic abstractions related to dispatching event symfony/finder v5.0.7 Symfony Finder Component symfony/http-foundation v5.0.7 Symfony HttpFoundation Component symfony/http-kernel v5.0.7 Symfony HttpKernel Component symfony/mime v5.0.7 A library to manipulate MIME messages symfony/polyfill-ctype v1.15.0 Symfony polyfill for ctype functions symfony/polyfill-iconv v1.15.0 Symfony polyfill for the Iconv extension symfony/polyfill-intl-idn v1.15.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-mbstring v1.15.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.15.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.15.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/process v5.0.7 Symfony Process Component symfony/psr-http-message-bridge v2.0.0 PSR HTTP message bridge symfony/routing v5.0.7 Symfony Routing Component symfony/service-contracts v2.0.1 Generic abstractions related to writing services symfony/translation v5.0.7 Symfony Translation Component symfony/translation-contracts v2.0.1 Generic abstractions related to translation symfony/var-dumper v5.0.7 Symfony mechanism for exploring and dumping PHP variables theseer/tokenizer 1.1.3 A small library for converting tokenized PHP source code into XML and potentially other formats tijsverkoyen/css-to-inline-styles 2.2.2 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This i... vlucas/phpdotenv v4.1.4 Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically. voku/portable-ascii 1.4.10 Portable ASCII library - performance optimized (ascii) string functions for php. webmozart/assert 1.8.0 Assertions to validate method input/output with nice error messages.

Strange thing though, I'm using XAMPP under windows no error. This error came when I did the upgrade in the staging which is running in linux.

b-cil commented 4 years ago

hi again,

I had to roll back to laravel v6 & symfony v4 in order not to have the error.

kylekatarnls commented 4 years ago

This is a very probable duplicate of #2033. You're maybe not running PHP 7.4 on the environment that throws this error.

b-cil commented 4 years ago

I solved it by deleting migrating to laravel 7 & symfony 5, deleting all vendor files and reinstalling everything...

iBotPeaches commented 4 years ago

I can't seem to resolve this, with the same error mentioned above. It is isolated to one production environment, so we halted deployment to the rest to investigate.

It is not reproducible locally with same exact php version (7.3.14), so I thought it was related to autoload or something. Nothing like that panned out.

I'm tired and out of ideas, but it appears to be related to this commit: https://github.com/briannesbitt/Carbon/commit/e2aa6ee1f4c87699f71d5e1d047ae48ea55ebbb3#diff-8cf8971551b5758d304f5a8131a9674fR21 - where the class alias runs.

It must be opcode/cache related. My guess is somehow interface_exists on an if check in a trait might be cached via opcode is some strange way but really just guessing.

I don't have anything actionable yet, but Google led me to this ticket so adding my 2c.


EDIT - Resolved here. Our deployment process was not deleting old composer files, so the vendor directory for Carbon had files that had since been removed, thus messing with the logic. Leading to this goose chase. Apologies.

b-cil commented 4 years ago

thank you ! Have a lovely day...

kylekatarnls commented 4 years ago

To be noted, code cache like OPCache should be cleaned/regenerated on deploy, or at least on deploy after an upgrade of important dependencies such as your framework.

vikranthouzeo commented 3 years ago

Delete vendor folder and composer update