Skip to content

Inconsistent behaviour with ::class in routes file. #26763

@sustained

Description

@sustained
  • Laravel Version: 5.7.5
  • PHP Version: 7.1.23
  • Database Driver & Version: N/A

Description:

Presume the following two lines of code are present at the end of all four following examples:

Route::resource('threads', ThreadController::class);
Route::post('/threads/{thread}/replies', [ReplyController::class, 'store']);

Depending on the use statements, things either work or don't or some variation thereof:

Example 1

use App\Http\Controllers\ReplyController;
// All routes work.

Example 2

// (No use statements)
// Only the routes on the threads resource work, otherwise:
// ReflectionException, Function () does not exist

Example 3

use App\Http\Controllers\ThreadController;
use App\Http\Controllers\ReplyController;
// Only the store reply route works, otherwise:
// App\Http\Controllers\App\Http\Controllers\ThreadController does not exist

Example 4

use App\Http\Controllers\ThreadController;
// None of the routes work.
// App\Http\Controllers\App\Http\Controllers\ThreadController does not exist

I would expect either #2 or #3 to be the one where all routes work?

Surely this is unintended behaviour. It's a little confusing to me.

Steps To Reproduce:

  1. Scaffold a new laravel project
  2. php artisan make:controller ThreadController -r
  3. php artisan make:controller ReplyController -r
  4. Try the 4 combinations of use statements above, with the 2 route declarations below.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions