解析错误:语法错误,意外的“|”,期望变量 (T_VARIABLE) [closed]

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) [closed]

提问人:yan naing 提问时间:5/13/2023 更新时间:5/13/2023 访问量:1660

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

6个月前关闭。

当我托管laravel项目时,我收到错误消息,我该怎么办? 错误消息是

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in /home/vol18_2/epizy.com/epiz_34191254/htdocs/BCM_Bank/vendor/nunomaduro/termwind/src/Functions.php on line 17

我的 Composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "carbondate/carbon": "*",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/breeze": "^1.20",
        "laravel/framework": "^10.8",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8",
        "livewire/livewire": "^2.12",
        "simplesoftwareio/simple-qrcode": "^4.2"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.1",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
         "platform": {
            "php": "8.1"
         },
        "platform-check": false,
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

错误文件 函数 .php

<?php

declare(strict_types=1);

namespace Termwind;

use Closure;
use Symfony\Component\Console\Output\OutputInterface;
use Termwind\Repositories\Styles as StyleRepository;
use Termwind\ValueObjects\Style;
use Termwind\ValueObjects\Styles;

if (! function_exists('Termwind\renderUsing')) {
    /**
     * Sets the renderer implementation.
     */
    function renderUsing(OutputInterface|null $renderer): void
    {
        Termwind::renderUsing($renderer);
    }
}

解析错误:语法错误,意外的“|”,期望变量 (T_VARIABLE) 在 /home/vol18_2/epizy.com/epiz_34191254/htdocs/BCM_Bank/vendor/nunomaduro/termwind/src/Functions 中.php第 17 行

php laravel 语法错误

评论


答:

1赞 Tangentially Perpendicular 5/13/2023 #1

函数的声明包括一个联合类型声明,但在 PHP 8.0 之前不支持该语法。升级 PHP 安装。renderUsing()OutputInterface|null

function renderUsing(OutputInterface|null $renderer): void
{
    Termwind::renderUsing($renderer);
}

评论

0赞 yan naing 5/13/2023
Laravel应用程序在我的本地环境中运行良好,我目前正在使用php 8.1.10。当我尝试在 Infinityfree 中托管时出现错误。几分钟前我发现托管服务器的php版本是7.4.8。因此,如果我降级我的 php 并重新创建 laravel 应用程序会工作吗?
1赞 Tangentially Perpendicular 5/13/2023
@yan我不知道。Laravel不是我的菜。不再支持 PHP 7.4,因此您最好在主机上升级 PHP。如果他们不能/不会这样做,请找一个更好的主机。
0赞 yan naing 5/13/2023
谢谢先生。你的回答对我有很大帮助。祝你有美好的一天