Skip to content
Advertisement

How to use class named “Case”?

I have a model class named Case in namespace App. When I try to use it I get:

syntax error, unexpected ‘Case’ (T_CASE), expecting identifier (T_STRING) or ‘{‘

Source code, error is on the line with use AppCase:

<?php

namespace AppHttpControllers;

use AppCase;
use AppHttpRequestsCaseStoreRequest;
use AppHttpRequestsCaseUpdateRequest;
use IlluminateHttpRequest;

class CaseController extends Controller {
/* ... */
}

How to escape class name in use declaration?

I’m using PHP 7.4.4 and framework Laravel 7.

Advertisement

Answer

case is a reserved keyword in PHP (https://www.php.net/manual/en/reserved.keywords.php), so you cannot use it as a class name.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement