一.现状
laravel 版本:5.4.36,php版本:7.0.13,composer install 包后,正常运行
php版本升级到7.3.4,composer install 包后,就会报 production.ERROR: ErrorException: compact(): Undefined variable: operator *错误
二.对比代码
最后对比了两个版本的框架核心源码,发现是 \vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php 下的 addWhereExistsQuery 方法
php-7.0.13版本
public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';$this->wheres[] = compact('type', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
php-7.3.4版本
public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
多了一个 operator 参数,删掉之后就解决问题了