我正在使用与 swagger 集成的流明来编写 Rest api。我遇到的问题是,即使数组中的键存在,php的isset()方法也返回 false,提到的是我的代码。
$this->setDataCenterHost(isset($aData[self::TBL_NAME.self::COL_HOST]) ? $aData[self::TBL_NAME.self::COL_HOST] : $aData[self::COL_HOST]);
这是有问题的陈述
isset($aData[self::TBL_NAME.self::COL_HOST])
当我像这样回应它时
echo $aData[self::TBL_NAME.self::COL_HOST]
它返回datacenter_host_name
在setDataCenterHost函数中使用与 isset 相同的语句会返回 false。
非常感谢任何帮助。
提到的是全班
class DTDataCenter
{
const DATACENTER_ID = 'id';
const DATACENTER_NAME = 'name';
const DATACENTER_IP = 'ping_ip_address';
const DATACENTER_HOST = 'host_name';
const DATACENTER_ISO = 'iso2';
const DATACENTER_LATT = 'laitude';
const DATACENTER_LONG = 'longitude';
const COL_ID = 'id';
const COL_NAME = 'dc_name';
const COL_IP = 'ping_ip_address';
const COL_HOST = 'host_name';
const TBL_NAME = 'datacenter_';
protected $_oId;
protected $_oName;
protected $_oHost;
protected $_oIp;
/**
* DTProtocol constructor.
* @param $_oId
*/
public function __construct($aData)
{
$this->setBaiscInfo($aData);
}
/**
* @return mixed
*/
function jsonSerialize()
{
return $this->getJson();
}
/**
* @return mixed
*/
public function getJson()
{
return array(
self::DATACENTER_ID =>$this->getDataCenterId(),
self::DATACENTER_NAME =>$this->getDataCenterName(),
self::DATACENTER_IP =>$this->getDataCenterIp(),
self::DATACENTER_HOST =>$this->getDataCenterHost()
);
}
public function setBaiscInfo($aData)
{
//Helper::dumpAndDie($aData);
$this->setDataCenterId(isset($aData[self::TBL_NAME.self::COL_ID]) ? $aData[self::TBL_NAME.self::COL_ID] :$aData[self::COL_ID] );
$this->setDataCenterName(isset($aData[self::TBL_NAME.self::COL_NAME]) ? $aData[self::TBL_NAME.self::COL_NAME] : $aData[self::COL_NAME]);
$this->setDataCenterIp(isset($aData[self::TBL_NAME.self::COL_IP]) ? $aData[self::TBL_NAME.self::COL_IP] : $aData[self::COL_IP]);
$this->setDataCenterHost(isset($aData[self::TBL_NAME.self::COL_HOST]) ? $aData[self::TBL_NAME.self::COL_HOST] : $aData[self::COL_HOST]);
// Helper::dumpAndDie($aData);
}
public function setDataCenterId($iId)
{
$this->_oId = new DTInteger($iId);
}
public function setDataCenterName($sName)
{
$this->_oName = new DTString($sName);
}
public function setDataCenterIp($sIp)
{
$this->_oIp = new DTString($sIp);
}
public function setDataCenterHost($sHost)
{
$this->_oHost = new DTString($sHost);
}
public function getDataCenterId()
{
return $this->_oId;
}
public function getDataCenterName()
{
return $this->_oName;
}
public function getDataCenterIp()
{
return $this->_oIp;
}
public function getDataCenterHost()
{
return $this->_oHost;
}
}