如何解决从 PHP 5 升级到 7创建的数组仅使用空值,然后才创建空数组
如果 $values=null 之前,则 $values 之后的值将为 null 或空数组。现在它似乎做到了 [0=>空]
发生了什么变化?
if(!is_array($values)) {
$values = array($values);
}
/**
* Search for Imaging group report data by sysi code. Optionally
* specify a Banner username to narrow the search.
*
* @param Mixed $sysiCodes
* @param String $username
*/
public function searchBySysiCode($sysiCodes,$username = '%',$sort = 'user')
{
$imagingModuleDataAccess = new ImagingModuleDataAccess();
$imagingGroupDataAccess = new ImagingGroupDataAccess();
$op = '';
/* Retreive modules and build a search string based on the
specified sysi codes. This is required to ensure we exclude
"private" sysi codes and groups that cannot be requested
for access. */
$module = null;
if(is_array($sysiCodes))
{
foreach($sysiCodes as $sysiCode)
{
$module = $imagingModuleDataAccess->searchBySysiCode($sysiCode)->first();
if($module != null)
{
$searchString .= $op . $imagingGroupDataAccess->getGroupMapSearchString($module);
}
$op = ' or ';
}
}
else
{
$module = $imagingModuleDataAccess->searchBySysiCode($sysiCodes)->first();
if($module != null)
{
$searchString = $imagingGroupDataAccess->getGroupMapSearchString($module);
}
}
$searchString = " and ( $searchString ) ";
// Add the username if specified.
if($username != null && $username != '%')
{
$searchString .= ' and ae_login.usrnam like upper(?) ';
$values = $username;
}
// Add sorting option.
switch ($sort)
{
case 'user':
$searchString .= ' order by ae_login.usrnam,ae_als.aliasname ';
break;
case 'group':
default:
$searchString .= ' order by ae_als.aliasname,ae_login.usrnam ';
break;
}
return $this->search($searchString,$values);
}
/**
* Function used to access underlying datastore handle
*
* @param string $searchString sql where clause for search
* @param array $values bind values for sql
* @return mixed return type based on RETURNTYPE code
*/
protected function search($searchString,$values)
{
$return = '';
$sql = "select distinct
ae_login.usrnam,ae_als.aliasid,ae_als.aliasname,ae_als.aliasdesc
from
otgmgr.ae_als,otgmgr.ae_login,otgmgr.ae_amap
where
1 = 1
and ae_amap.usrid = ae_login.usrid
and ae_als.aliasid = ae_amap.aliasid
$searchString ";
try
{
$return = $this->retrieve($sql,$values);
}
catch(Exception $e)
{
throw $e;
}
return $return;
}
protected function retrieve($sql,$values=array())
{
// The result set to return.
$return = '';
/* Doctrine DBAL */
if(!is_array($values)) {
$values = array($values);
}
$stmt = $this->dataSource->executeQuery($sql,$values);
// Determine what type of result to return.
if ($this->returnType == RETURNTYPE_RAW) {
$return = $stmt;
} else if ($this->returnType == RETURNTYPE_ARRAY) {
$return = $this->getArray($stmt);
} else if ($this->returnType == RETURNTYPE_ASSOC) {
$return = $this->getAssoc($stmt);
} else if ($this->returnType == RETURNTYPE_IteraTOR) {
$return = $this->getIterator($this->getArray($stmt));
} else {
throw new Exception('Invalid returnType ' . $this->returnType);
}
return $return;
}
解决方法
在比较 PHP 5 和 7 时,本示例中实际上没有任何变化。
据我从您的代码片段中得知,您可以将空值作为第二个参数传递给 retrieve($sql,$values=array())
。
如果条件允许,这可能发生if($username != null && $username != '%')
在方法中searchBySysiCode($sysiCodes,$username = '%',$sort = 'user')
不见面。
您可以在 $values
方法的开头定义 searchBySysiCode
变量,这样您就不会将 null
值放入 retrieve
方法的第二个参数中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。