PHP 7.0.5 (cli) (built: Mar 31 2016 06:38:53) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
[0] Exception in Model.php line 500
no data to delete without where
if (!empty($options) && empty($options['where'])) {
// AR模式分析主键条件
$this->parsePkWhere($options); //问题出在这一步
}
// 分析表达式
$options = $this->_parseOptions($options);
if (empty($options['where'])) {
// 如果条件为空 不进行删除操作 除非设置 1=1
throw new Exception('no data to delete without where');
}
问题出在parsePkWhere这个方法 这里使用了地址引用 后面对$options操作由string转成array出错 ,在这个方法中输出变量$options正常,但是返回到delete()方法中就出错了
protected function parsePkWhere(&$options)
{
$pk = $this->getPk();
if (is_string($pk)) {
// 根据主键查询
if (is_array($options)) {
// 判断是否索引数组
if (0 === key($options)) {
$where[$pk] = ['in', $options];
} else {
return;
}
} else {
$where[$pk] = strpos($options, ',') ? ['IN', $options] : $options;
}
$options = []; //从这一步开始 option并没有写入到地址引用的值中 但是php并没有报错
$options['where'] = $where;//所以这一步也就无从设定说起 但是又不是没有作用
//var_dump($options); output array(1) { ["where"]=> array(1) { ["id"]=> string(1) "3" } }
} elseif (is_array($pk) && is_array($options) && !empty($options)) {
// 根据复合主键查询
$array = array_intersect_key($options, $pk);
if (count($pk) == count($array)) {
$options = array_diff_key($options, $array);
$options['where'] = array_combine($pk, $array);
} else {
throw new Exception('miss complex primary data');
}
}
return;
}
}
if (!empty($options) && empty($options['where'])) {
// AR模式分析主键条件
$this->parsePkWhere($options);
// var_dump($options); output array(1) { ["id"]=> string(1) "3" }
}