【PHP composer】elasticsearc包报错:"filter_var(): explicit use of FILTER_FLAG_SCHEME_REQUIRED and FILTER_

1.出现这个问题的原因是 PHP7.3 的 filter_var() 函数放弃了对这两个参数的支持。

/**
 * @param string $host
 *
 * @return string
 */
private function prependMissingScheme($host)
{
    if (!filter_var($host, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
       $host = 'http://' . $host;
    }
    return $host;
}

php 官方文档log如下:

https://www.php.net/manual/en/filter.filters.flags.php

所以当我们的 PHP version >= 7.3 时,使用 elasticsearch 的composer 包就会报这个错:

filter_var(): explicit use of FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED is deprecated

2.那么如何修复这个问题呢?同样在 elasticsearch-PHP 的官方开源包里也给了答案。

有兴趣可以看下这个讨论帖:

https://github.com/summerblue/laravel-shop/issues?utf8=%E2%9C%93&q=is%3Aissue+filter_var

我们将 composer.json 里的 elasticsearch 版本设置为 ‘^6.1.0’ 就不会报这个错了。

"elasticsearch/elasticsearch": "^6.1.0",

composer up -vvv 更新一遍包就行了。

祝大家 coding 愉快~

你可能感兴趣的:(PHP开发,MySQL,后端)