【问题标题】:Error in Laravel vendor files: Warning: Unsupported declare 'strict_types' in Laravel 5.3Laravel 供应商文件中的错误:警告:Laravel 5.3 中不支持声明“strict_types”
【发布时间】:2018-05-16 02:57:18
【问题描述】:

由于某种原因在我的 Laravel 5.3 应用程序上运行 composer update 时出现以下错误

警告:不支持在 /home/site/public_html/bookings/vendor/league/csv/src/functions.php 在第 13 行

我认为这可能与 PHP 版本有关,因为它无法识别 PHP 7 类型结构,我在我的服务器上运行 PHP 7.0.25 但是当我在我的控制台中运行 php -v 时,当我 ssh 进入服务器时它显示 PHP 5.6.32。

有人知道为什么它对这个核心文件抱怨吗?我没有触及供应商文件夹中的任何文件。

这是该文件的内容:

<?php
/**
* This file is part of the League.csv library
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
* @version 9.1.1
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace League\Csv;

use ReflectionClass;
use Traversable;

/**
 * Returns the BOM sequence found at the start of the string
 *
 * If no valid BOM sequence is found an empty string is returned
 *
 * @param string $str
 *
 * @return string
 */
function bom_match(string $str): string
{
    static $list;

    $list = $list ?? (new ReflectionClass(ByteSequence::class))->getConstants();

    foreach ($list as $sequence) {
        if (0 === strpos($str, $sequence)) {
            return $sequence;
        }
    }

    return '';
}

/**
 * Detect Delimiters usage in a {@link Reader} object
 *
 * Returns a associative array where each key represents
 * a submitted delimiter and each value the number CSV fields found
 * when processing at most $limit CSV records with the given delimiter
 *
 * @param Reader   $csv        the CSV object
 * @param string[] $delimiters list of delimiters to consider
 * @param int      $limit      Detection is made using up to $limit records
 *
 * @return int[]
 */
function delimiter_detect(Reader $csv, array $delimiters, int $limit = 1): array
{
    $found = array_unique(array_filter($delimiters, function (string $value): bool {
        return 1 == strlen($value);
    }));
    $stmt = (new Statement())->limit($limit)->where(function (array $record): bool {
        return count($record) > 1;
    });
    $reducer = function (array $result, string $delimiter) use ($csv, $stmt): array {
        $result[$delimiter] = count(iterator_to_array($stmt->process($csv->setDelimiter($delimiter)), false), COUNT_RECURSIVE);

        return $result;
    };
    $delimiter = $csv->getDelimiter();
    $header_offset = $csv->getHeaderOffset();
    $csv->setHeaderOffset(null);
    $stats = array_reduce($found, $reducer, array_fill_keys($delimiters, 0));
    $csv->setHeaderOffset($header_offset)->setDelimiter($delimiter);

    return $stats;
}

if (!function_exists('\is_iterable')) {
    /**
     * Tell whether the content of the variable is iterable
     *
     * @see http://php.net/manual/en/function.is-iterable.php
     *
     * @param mixed $iterable
     *
     * @return bool
     */
    function is_iterable($iterable): bool
    {
        return is_array($iterable) || $iterable instanceof Traversable;
    }
}

/**
 * Tell whether the content of the variable is an int or null
 *
 * @see https://wiki.php.net/rfc/nullable_types
 *
 * @param mixed $value
 *
 * @return bool
 */
function is_nullable_int($value): bool
{
    return null === $value || is_int($value);
}

【问题讨论】:

  • 请参阅:可能重复 stackoverflow.com/questions/35746444/… 不幸的是,它没有经过检查的答案,但 OP 自己回答了。要点是确保安装了mbstring
  • @ArtisticPhoenix 是的,这个问题没有可接受的答案,而且这个问题是 Laravel 特有的,因为错误发生在 Laravel 包中。
  • 这是一个 PHP 错误,仅仅因为它发生在 Lavavel 中并不意味着它只是 Lavavel 的事情。在你的项目之外创建一个单独的 PHP 文件,看看会发生什么。
  • 不管怎样,这个问题没有用。
  • 您是否安装了mbstring 扩展程序?我并不是说这是正确的答案,但是……就我个人而言,我看不出有任何理由在 Web 应用程序上严格打字,这不是但令人沮丧。

标签: php laravel php-7


【解决方案1】:

您的服务器网络启用了 PHP 7(如果您从 phpinfo(); 获取它),但您的服务器的 CLI 没有。您尝试运行的命令正在从控制台运行。

CLI 和 WEB PHP 版本没有区别。

如果您的服务器是基于 Debian 的 (Ubuntu)。 查看 /etc/php 并查看是否有多个 PHP 版本,如果有,您可以创建符号链接以将您的 CLI 版本也链接到 PHP 7

sudo ln -sfn /usr/bin/php7.0 /usr/bin/php

【讨论】:

    猜你喜欢
    • 2021-02-02
    • 2016-06-15
    • 1970-01-01
    • 2016-07-28
    • 2017-09-24
    • 1970-01-01
    • 2017-07-13
    • 2019-09-28
    相关资源
    最近更新 更多