Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ricardogolez's avatar

error in using Class as model name

I have a model called Class and User.

my User model has this line of code.

use App\Class; its giving me an error "syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING)"

but when I use other names its just fine. could someone tell me why its not possible to use the word Class as a classname

0 likes
3 replies
bryse's avatar
bryse
Best Answer
Level 4

You are receiving this error because "class" is a reserved keyword in PHP.

You can find a list of all reserved keywords at the following URL: http://php.net/manual/en/reserved.keywords.php

Perhaps you can use Classroom, Lesson, or Type instead?

2 likes
akash.mishra's avatar

Yes, I will vote for @brysem answer here. We should not use any of Reserved keywords to declare variable, class or method name. It will raise error for sure.

You may also like article on QuizCure regarding Reserve Keyword.

Please or to participate in this conversation.