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

westiti's avatar

syntax error, unexpected token "new" when accessing Volt full page component

Hello, I created a volt component that I want to use as a full-page component:

<?PHP
use Livewire\Volt\Component;

new class extends Component {
    // Your class code here
};
?>

<div>
    Hello
</div>

This is the route definition:

Volt::route('feature', 'feature')->name('feature');

But when I try to load the page in the browser I get this error message syntax error, unexpected token "new"

I'm new to Volt so I don't know if I did something wrong. Any help would be appreciated and thanks

0 likes
6 replies
Tray2's avatar

You don't use new in the class definition, you use that when you create an instance of the class.

class MyClass extends SomeOtherClass 
{
}

$myClass = new MyClass();

So remove the new from your class.

westiti's avatar

@Tray2 the new is required for Volt components as mentioned in the documentation and removing it throw another error syntax error, unexpected token "extends", expecting identifier

Snapey's avatar

you need use Livewire\Volt\Component; before your new line

westiti's avatar

@Snapey use Livewire\Volt\Component; is included because it's a generated component

Snapey's avatar

@westiti Its not in the code you posted, so do you want to show us the real code?

if the framework generated the component would start <?php

Edit: oh, I see you helpfully edited your question

westiti's avatar

I finally found the issue. It turns out there was a livewire attribute that was placed in the wrong location. I didn't notice it because I thought it was a comment. So instead of this:

#[Title('Feature 1')]
new class extends Component {
    // Your class code here
};

It should be like this:

new #[Title('Feature 1')]  class extends Component {
    // Your class code here
};

I hope this helps anyone else who has encountered the same problem.

Please or to participate in this conversation.