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

sherwinmdev's avatar

class name class?

i use phpstorm as an IDE. i have a model named class that contains information about classes as in school classes. so i would think to use class as the name of the class. the IDE reports it as a possible error. before moving forward would it be an error?

// Class model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Class extends Model
{
    protected $table = 'classes';

    /**
     * Class belongs to program type.
     * @return mixed
     */
    public function programType()
    {
        return $this->belongsTo(ProgramType::class);
    }
}

// Program Types model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProgramType extends Model
{
    protected $table = 'program_types';
    public $timestamps = false;

    /**
     * Program type has many classes.
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function classes()
    {
        return $this->hasMany(Class::class);
    }
}

i think i ran into something similar with a model called Event but it worked out alright.

if this doesn't work, should i use a different name - what name? or use the plural?

0 likes
7 replies
Shahrukh4's avatar

You can't use the fixed keywords as your class names and all..try some other names rather than naming them same as library defined names.

No, I don't think it have to be plural, make it as simple as possible and singular.

2 likes
sherwinmdev's avatar

@Shahrukh4 @bobbybouwmann thank you.

i'll keep it as is. i think the IDE is set to be sensitive by default. right now i'm just building models and seeders. i'm moving data from mssql to mysql as an experiment project.

i won't know if it becomes an issue until i write tests. if it does fail, i'll just refactor that model. luckily the relationship only exists in 2 other models. i just want to get the data over and play with it in laravel - cleaning things up in the process.

Shahrukh4's avatar

Well may be it will not occur any issue sometimes but it is a good practice not to use the reserved keywords as your class names and methods rather make your own.

1 like
Cronix's avatar

I'd call it "Course". Using "Class" will come back to bite you and might as well avoid that from the get-go so you don't have to refactor it all later.

1 like

Please or to participate in this conversation.