无法转换类型为的PHP值。。。键入。。。。应为以下类型之一:null,DateTime

无法转换类型为的PHP值。。。键入。。。。应为以下类型之一:null,DateTime,php,symfony,Php,Symfony,当我使用Symfony3.4支持自动布线并移动命令时,出现了以下错误。 具体来说,添加\u构造并更改$this->getContainer()->get('database\u connection') 到$this->connection它已更改。 有什么问题吗 错误 UpdateAccessReportCommand.php 使用条令\DBAL\Connection; 受保护的$连接; 公共函数构造(连接$Connection) { $this->connection=$connection

当我使用Symfony3.4支持自动布线并移动命令时,出现了以下错误。
具体来说,添加
\u构造
并更改
$this->getContainer()->get('database\u connection')
$this->connection
它已更改。
有什么问题吗

错误

UpdateAccessReportCommand.php

使用条令\DBAL\Connection;
受保护的$连接;
公共函数构造(连接$Connection)
{
$this->connection=$connection;
父项::_构造();
}
/**
*命令执行
*@param InputInterface$input
*@param OutputInterface$output
*@可丢弃
*/
受保护的函数执行(InputInterface$input,OutputInterface$output)
{
$date=new\DateTime($input->getOption('date'));
$week=$this->getFirstDayOfWeek($date);
$month=new\DateTime($date->format('Y-m-01');
$this->connection->transactional(函数()使用($date、$week、$month){
//更新每日访问报告
$this->deleteAccessReportDaily($this->connection,$date);
$this->insertAccessReportDaily($this->connection,$date,'portal');
$this->insertAccessReportDaily($this->connection,$date,'brand');
$this->insertAccessReportDaily($this->connection,$date,'shop');
$this->insertAccessReportDaily($this->connection,$date,'article');
});
}
ConversionException.php

/**
*当传递给转换器的PHP值不是预期类型时引发。
*
*@param混合$value
*@param string$toType
*@param string[]$possibleTypes
*
*@return ConversionException
*/
公共静态函数转换失败ValidType(
$value,
$toType,
数组$possibleTypes,
?可丢弃的$previous=null
) {
$actualType=is_object($value)?get_class($value):gettype($value);
if(是_标量($value)){
返回新自我(sprintf)(
“无法将类型为“%s”的PHP值“%s”转换为类型“%s”。应为以下类型之一:%s”,
$value,
$actualType,
$toType,
内爆(“,”,$possibleTypes)
),0元,$先前);
}
//第88行
返回新自我(sprintf)(
“无法将“%s”类型的PHP值转换为“%s”类型。应为以下类型之一:%s”,
$actualType,
$toType,
内爆(“,”,$possibleTypes)
),0元,$先前);
}

当我读取错误字符串时,它告诉您正在将连接对象传递给函数的参数,该函数应为:null(nothing)或B:DateTime对象

我看不出哪一行是第88行,但根据你的错误,这就是问题所在

跟进问题:

$this->connection->transactional是否应该有一个连接参数


希望这能进一步帮助你

谢谢你的回答。当然,我在想,原来
function()
是以
function($connection)
的形式出现的<代码>函数($this->connection)
是一个语法错误,
函数($connection)
给出了一个类似的错误。是否有方法检查
事务性
是否有连接参数?我认为使用
var\u dump
很困难。另外,为了以防万一,我添加了第88行。
[root@localhost Symfony]# php bin/console ahisp:analytics:update-article-pageview

16:46:32 ERROR   [console] Error thrown while running command "ahisp:analytics:update-access-report". 
Message: "Could not convert PHP value of type 'Doctrine\DBAL\Connection' to type 'date'. 
Expected one of the following types: null, DateTime" ["exception" => Doctrine\DBAL\Types\ConversionException { …},
"command" => "ahisp:analytics:update-access-report",
"message" => "Could not convert PHP value of type 'Doctrine\DBAL\Connection' to type 'date'. 
Expected one of the following types: null, DateTime"] In ConversionException.php line 88:

Could not convert PHP value of type 'Doctrine\DBAL\Connection' to type 'date'. Expected one of the following types: null, DateTime