0

The error I'm getting here is:

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?

4
  • 11
    CASE is a reserved word in PHP, used as part of a switch statement Commented May 29, 2014 at 11:41
  • yes CASE is a reserved word. Please change to some other name. Commented May 29, 2014 at 11:42
  • I'm aware of that but assumed it's not that because it's uppercase. Commented May 29, 2014 at 11:42
  • PHP doesn't care much about that. Commented May 29, 2014 at 11:43

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Would have +1'ed this had Mark not commented before you :p
@aspirin: you said it. :P
0

First of all you should know that PHP is not case sensitive. So "case", "Case", "caSE", "CAsE" and like are same thing.

And you already know that case is a php reserved keyword it can't be use for variable name.

You can initialize your class like $obj = new PartCategories();
or paRTCATEgories();
or PARTCATEGORIES();
mEANS tO sAY THAt PHp iS CaSE INSEnsitive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.