0

I have a Class.php file and I am trying to use it in another file.

use App\Class; 

However, I get this error:

syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING)

Is there any way to use Class in my namespace or do I have to rename it?

2 Answers 2

1

You can't use reserved words as class names! It is anyway a bad idea, because you should use a meaningful name for it - you will forget what it was for one day.

Just in case you didn't want to use the class "Class" - because that is what use App\Class is gonna try, you can include files using include('Class.php');

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

Comments

0

Do you have a class named Class inside that file? the use statement is for loading classes not "just" a file.

anyway you can't use Class as a class name or namespace segment as it's a reserved word

2 Comments

Yes there is a class named Class.
to be sure i tested it: you can't have a class named Class, it will raise a PHP Parse error: syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING) in …

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.