top-think / top-think/think-orm
在php7.3及以上版本中,会出错
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
代码位置 :\topthink\think-orm\src\db\BaseQuery.php
原代码:
public function field($field)
{
if (empty($field)) {
return $this;
} elseif ($field instanceof Raw) {
$this->options['field'][] = $field;
return $this;
}
if (is_string($field)) {
if (preg_match('/[\<\'\"\(]/', $field)) {
return $this->fieldRaw($field);
}
$field = array_map('trim', explode(',', $field));
}
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields();
$field = $fields ?: ['*'];
}
if (isset($this->options['field'])) {
$field = array_merge((array) $this->options['field'], $field);
}
$this->options['field'] = array_unique($field);
return $this;
}
修改为
public function field($field)
{
if (empty($field)) {
return $this;
} elseif ($field instanceof Raw) {
$this->options['field'][] = $field;
return $this;
}
if (is_string($field)) {
if (preg_match('/[\<\'\"\(]/', $field)) {
return $this->fieldRaw($field);
}
$field = array_map('trim', explode(',', $field));
}
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields();
$field = $fields ?: ['*'];
}
if (isset($this->options['field'])) {
$field = array_merge((array) $this->options['field'], $field);
}
$this->options['field'] = @array_unique($field);
return $this;
}
$this->options['field'] = array_unique($field); 这一行增加一个@,忽略报错,否则有时联表分组查询后,先查count,再查select会报错。如下图:

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open topthink/think-orm/src/db/BaseQuery.php and inspect BaseQuery::field(), especially the array_unique call after a count query followed by a select in a grouped join. Reproduce the reported PHP 7.3+ warning using the linked screenshot scenario, then verify that the follow-up select completes without the reported error and that existing ORM behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100