The following warning occurs when calling setTimezone() on ChronosDate is done from within a function:
PHP Warning: Undefined array key "class" in /srv/www/vendor/cakephp/chronos/src/Traits/FrozenTimeTrait.php on line 166
How i reproduced it locally?
$date = new ChronosDate();
// example when called from within a function like twig does when configured in symfony
function foo(ChronosDate $date) {
$date->setTimezone("Europe/Amsterdam");
}
foo($date);
The output:
PHP Warning: Undefined array key "class" in /srv/www/vendor/cakephp/chronos/src/Traits/FrozenTimeTrait.php on line 166
PHP Deprecated: 2.5 setTimezone() will be removed in 3.x. in /srv/www/vendor/cakephp/chronos/src/Traits/FrozenTimeTrait.php on line 175
How did i run into this?
When upgrading from v2.2 to 2.4 and running a project on symfony 6 which uses twig configuration to handle date filters.
Additional information related to debugging the issue for our symfony / twig situation
When added the dd($trace) in that trait:
public function setTimezone($value)
{
if (static::class === ChronosDate::class) {
$trace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 5);
$found = false;
dd($trace);
foreach ($trace as $frame) {
$found = in_array(
$frame['class'],
['PHPUnit\Framework\Assert', 'PHPUnit\Framework\Constraint\IsEqual'],
true
);
if ($found) {
break;
}
}
if (!$found) {
trigger_error('2.5 setTimezone() will be removed in 3.x.', E_USER_DEPRECATED);
}
}
return $this;
}
Description:
The following warning occurs when calling setTimezone() on ChronosDate is done from within a function:
How i reproduced it locally?
The output:
How did i run into this?
When upgrading from v2.2 to 2.4 and running a project on symfony 6 which uses twig configuration to handle date filters.
Additional information related to debugging the issue for our symfony / twig situation
When added the dd($trace) in that trait:
The following (partly) result is dumped:
For us this comment already applied to not go to v3. Unfortunately going to v2.4 is currently also not an option.