使用 DB 或 Eloquent 出错,提示 Unsupported operand types

搜索了三天,实在没招了,只好在这里斗胆提问了。

背景:
nginx+mysql+laravel5.6

测试:
DB::select('select * from tablename'); // 没问题
DB::table('tablename')->get(); //出错
tablename::select('foo')->get(); //出错

出错提示:Unsupported operand types
出错段落:

public static function flatten($array, $depth = INF)
        {
            $result = [];
            foreach ($array as $item) {
                $item = $item instanceof Collection ? $item->all() : $item;

                if (! is_array($item)) {
                    $result[] = $item;
                } elseif ($depth === 1) {
                    $result = array_merge($result, array_values($item));
                } else {
                    $result = array_merge($result, static::flatten($item, $depth - 1)); //些处为出错点
                }
            }

            return $result;
        }

这个问题非常奇怪,原生mysql查询一切正常,但无法使用DB和Eloquent功能,让人很无语啊。
希望能得到你们的帮忙,谢谢!

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

自己找到问题所在了!
其实是PHP版本问题,原来使用的是7.3的版本,现在改为7.2即正常了。
php7.2最好在webtatic.com上下载使用。
记住了这次教训,谢谢大家!给大家添麻烦了!

6年前 评论
zhouciming 6年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!