top-think / top-think/think-orm

TypeError: Return value of think\\db\\PDOConnection::pdoQuery() must be of the type array, bool returned in

Open
#468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

webman使用think-orm和think-cache
使用db的链式方法cache进行查询例如:
model::where([xxx,xxx])->cache(true,60)->find();
会报错

TypeError: Return value of think\\db\\PDOConnection::pdoQuery() must be of the type array, bool returned in ....

就是下面这个方法里面$data,当从缓存里面查询不到数据时候,变量值不只是null

/**
     * 执行查询 返回数据集
     * @access protected
     * @param BaseQuery $query  查询对象
     * @param mixed     $sql    sql指令
     * @param array     $bind   参数绑定
     * @param bool      $master 主库读取
     * @return array
     * @throws DbException
     */
    protected function pdoQuery(BaseQuery $query, $sql, array $bind = [], bool $master = null): array
    {
        // 分析查询表达式
        $query->parseOptions();

        if ($query->getOptions('cache')) {
            // 检查查询缓存
            $cacheItem = $this->parseCache($query, $query->getOptions('cache'));
            $key       = $cacheItem->getKey();

            $data = $this->cache->get($key);
           // 当从缓存里面查询不到数据时候,$data值不只是null,还可能是false,只判断null会造成报错
            if (null !== $data) {
                return $data;
            }
        }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating PDOConnection::pdoQuery() and inspect the cache lookup through $this->cache->get($key), especially the behavior when no cached data exists. Verify the cache-miss path with a chained query using cache(true, 60); done means a missing cache entry no longer causes the declared array return type to receive false.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.