【问题标题】:Fatal error - Parse error: syntax error, unexpected ':', expecting - Wordpress致命错误 - 解析错误:语法错误,意外':',期待 - Wordpress
【发布时间】:2019-05-16 05:51:10
【问题描述】:

我需要你的帮助。 我正在尝试安装 ACF 插件并给我这个错误:

解析错误:语法错误,意外 ':',期待 ';'或 '{' 在 /home/htb/mysite/wp-content/plugins/acf-for-woocommerce/vendor/catsplugins/cp-core/src/common/class-cp-util.php 第 23 行

这是第 23 行:

public static function pathToUrl(string $path): string {

代码如下:

<?php

namespace CastPlugin;


if (class_exists('CpUtil')) {
    return;
}


class CpUtil
{
    public static function startsWith($haystack, $needle)
    {
        return strncmp($haystack, $needle, strlen($needle)) === 0;
    }

    public static function contains($haystack, $needle)
    {
        return strpos($haystack, $needle) !== false;
    }

    public static function pathToUrl(string $path): string {
        $ssl          = @$_SERVER['HTTPS'];
        $serverName   = $_SERVER['SERVER_NAME'];
        $documentRoot = $_SERVER['DOCUMENT_ROOT'];
        $correctPath  = $path;

        $uri          = str_replace($documentRoot, '', $correctPath);

        $protocol = $ssl === 'on' ? 'https' : 'http';

        return "$protocol://$serverName$uri";
    }
}

知道如何解决这个问题吗? 谢谢你。 :)

【问题讨论】:

    标签: wordpress parsing plugins syntax


    【解决方案1】:

    您使用的 ACF 版本需要 PHP 7.0+。您收到的错误消息表明您使用的是 PHP 5.6 或更早版本。您应该与您的托管服务提供商讨论是否允许您升级到较新版本的 PHP。

    此错误是由 PHP 7.0 中引入的新 PHP 方法声明语法引起的,该语法允许您声明您定义的方法将返回一个数组,您可以在此处阅读:http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration

    如果您的托管服务提供商不会升级您的 PHP 版本,我建议您寻找新的托管服务提供商。但是,如果您同时需要 ACF 工作,您可以转到存储库中的 ACF 的 advanced 页面,并在页面底部下载旧版本。

    注意:这两种做法(使用过时的 PHP 版本和使用过时的插件)都可能不利于 WordPress 安装的长期健康。我建议您至少尽快使用 PHP 7.2,这将允许您使用最新版本的 ACF。

    【讨论】:

      猜你喜欢
      • 2021-11-05
      • 2016-01-29
      • 1970-01-01
      • 2012-06-17
      • 2013-06-28
      • 2011-09-22
      • 1970-01-01
      相关资源
      最近更新 更多