Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用奏鸣曲碳库中的当前年份_Php_Sonata - Fatal编程技术网

Php 如何使用奏鸣曲碳库中的当前年份

Php 如何使用奏鸣曲碳库中的当前年份,php,sonata,Php,Sonata,我是索纳塔的新手,我正在尝试使用碳库生成今年所有记录的输出 这是来自碳库 碳::Iscurrent year 没有争论 返回布尔 检查实例是否与当前时刻处于同一年。 方法添加了1.22.0无参数 下面是我试图应用的代码 public function getIsActiveThisYear(): bool { $now = Carbon::isCurrentYear(); $endofyear = $endDate->year; $

我是索纳塔的新手,我正在尝试使用碳库生成今年所有记录的输出

这是来自碳库 碳::Iscurrent year 没有争论 返回布尔 检查实例是否与当前时刻处于同一年。 方法添加了1.22.0无参数

下面是我试图应用的代码

 public function getIsActiveThisYear(): bool
    {
        $now = Carbon::isCurrentYear();
        $endofyear = $endDate->year;
        $startofyear = $startDate->year;
        return $this->$endofyear == $now || $this->$startofyear == $now;  
    }
此代码导致的错误为:

isCurrentYear does not exist
只要这样做:

$date = new DateTime(); // Carbon extends the PHP DateTime class so it's the same.
$thisYear = $date->format('Y');
检查文档!:-)

您还需要传递开始和结束日期

public function getIsActiveThisYear(DateTime $startDate, DateTime $endDate): bool

Carbon::isCurrentYear不是类的静态方法,它可以被称为
$date->isCurrentYear()
。顺便说一句,您的代码也没有意义$endDate和startDate是未查找的。