Back to blog 1 Minute
2026-02-09

Livewire 5 Cannot use "::class" on int

Livewire4Volt

I try to keep my blog up to date, and last weekend I finally managed to update Livewire from version 3 to 4.
But when I ran the tests, I got this error on my blog pages:

TypeError
Cannot use "::class" on int

The stack trace was even more confusing since it pointed at some middleware, and when I commented it out, it then pointed to another middleware.
Digging a little deeper, I found out that this actually happened when trying to load content out of the compiled blade views.

The culprit was then easily detected. The latest feature I added to the blog is the "table of contents", which is automatically generated from the headlines in my posts.
While the headlines are extracted in a centralized service, the actual output is created using several different view components.
And for these components, I used Volt.

Up to version 3, the usual Livewire component required a PHP class in addition to a Blade template file.
Volt is an extension of Livewire that allows for single-file components.

But since Livewire 4, single-file components are not just supported but the default, making Volt superfluous, which is why I already uninstalled it in the upgrade process.
That did not automatically get rid of all Volt components, though.

After that issue was found, the fix was trivial:

git_diff

Since my Volt components were as minimal as they could get, the change was trivial.

The syntax in Volt was extremely minimal, whereas the new Livewire approach contains a simple anonymous class.
This is also the reason for that strange error message. Livewire tried to load the class within that Blade template but could not find it.

Except for this small hiccup, the upgrade process was very straightforward.
Livewire 4 brings several improvements and new features, and I am eager to try them out.

Comments

There are no comments yet