Closed trevorpan closed 3 years ago
Hello, 👋
The code we need to analyze your issue is not the library method source code but how you call this method give an example with static values calling the method that trigger the error when we run it on https://try-carbon.herokuapp.com/
Then provide expected output: the result you expected for this call in this given example:
Thanks.
Hi Kyle,
Just to be clear, my code is not directly calling Carbon. This is the Laravel framework.
Wasn't sure to get exactly where or how it was called. The error's stack trace references:
#0 /..../vendor/nesbot/carbon/src/Carbon/Traits/Date.php(2532): Carbon\\Carbon->addRealUnit()
#1 /..../vendor/laravel/framework/src/Illuminate/Support/InteractsWithTime.php(37): Carbon\\Carbon->__call()
Here's the line, I tried assigning
$delay = 0;
Carbon::now()->addRealSeconds($delay)->getTimestamp();
in your handy program but the output was nothing.
Here's the method being called
/**
* Get the "available at" UNIX timestamp.
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @return int
*/
protected function availableAt($delay = 0)
{
$delay = $this->parseDateInterval($delay);
return $delay instanceof DateTimeInterface
? $delay->getTimestamp()
: Carbon::now()->addRealSeconds($delay)->getTimestamp();
}
Now, the first stack trace references this method: public function addRealUnit($unit, $value = 1)
(Carbon).
Wondering if that's a better method to call?
Also, is the program you sent using PHP 8?
Yes, https://try-carbon.herokuapp.com/ run PHP 8.0.2 as you can see if you type echo PHP_VERSION;
According to the error message you provided, an array
is passed instead of an int
, for instance you can reproduce the error with:
echo Carbon::now()->addRealSeconds([])->getTimestamp();
But []
is not expected to work, so this error is actually the correct behavior, and you probably need to check what you are passing to ->availableAt()
or check what is returned from $delay = $this->parseDateInterval($delay);
which is likely not what it should be (e.g. a number of second).
Hi @kylekatarnls well.
I thought it was an php8.0 error, as I'd just read up on the new features and specifically the stronger typing.
Was hoping my mistake might make an improvement to Carbon or Laravel .... instead I misconfigured the queue!
After following each and every stack I realized that it was on deploy the php artisan horizon:terminate
would call the those methods, but because the config/database.php
referenced phpredis
not predis
it gave it bad data and the error.
Anyhow, thank you very much... I'll certainly use the try-carbon app in the future if I find some Carbon related items..
just wanted to make an additional note here for anyone coming on this.
The real issue was not phpredis
vs. predis
it was this line: 'retry_after' => ['60', '120', '240'],
added to config/queue.php. This is where the array originated.
It's a little confusing because you can use exponential backoff as a property on a queued job for example, but the config/queue.php file accepts only a single value, such as: 'retry_after' => 90,
Hello,
I encountered an issue with the following code:
Carbon version: *versions : 2.46.0**
PHP version: PHP 8.0.3 (cli) (built: Mar 5 2021 07:54:13) ( NTS )
I expected to get:
But I actually get:
This is used with
Laravel 8.31
The above error crashes the site in production but not locally. I wasn't reading the $value as an array, but that was error. Not sure how to handle that, as you've declared in the doc block(int)
and then typed it on line 136.