声明常量时的PHP语法错误 [英] PHP syntax error when declaring a constant

查看:31
本文介绍了声明常量时的PHP语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里得到的错误是:

The error I'm getting here is:

解析错误:语法错误、意外的CASE"(T_CASE)、[文件名]中的预期标识符(T_STRING)4

Parse error: syntax error, unexpected 'CASE' (T_CASE), expecting identifier (T_STRING) in [filename] on line 4

<?php

class PartCategories {
    const CASE = 1;
    const PROCESSOR = 2;
    const HARD_DRIVE = 3;
    const MEMORY = 4;
}

不能说我已经尝试过任何东西,但我一生都看不到这里出了什么问题.

Can't say I've tried anything but for the life of me can't see what's wrong here.

为什么这是一个语法错误?

Why is this a syntax error?

推荐答案

caseCASE 已被 PHP 保留用于 switch 语句.您不能将其重新定义为常量,就像您不能定义 const FUNCTION 或类似的东西一样.

case or CASE is already reserved by PHP for the switch statement. You can't redefine this as a constant, just as you cant define a const FUNCTION or something similar.

您将不得不更改常量的名称.

You're going to have to change the name of the constant.

这篇关于声明常量时的PHP语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆