livewire / volt

Volt is an elegantly crafted functional API for Livewire.
https://livewire.laravel.com/docs/volt
MIT License
327 stars 19 forks source link

ParseError due to invalid method name containing an integer #45

Closed astersnake closed 1 year ago

astersnake commented 1 year ago

Volt Version

1.1

Laravel Version

10.21.0

PHP Version

8.2.8

Database Driver & Version

No response

Description

While using Laravel Volt with Livewire, encountering a ParseError with the message syntax error, unexpected integer "1". The error occurs in the compiled views stored in the storage/framework/views folder. All project dependencies are up to date. The code causing the error is embedded in the generated view file 362bf8caa4c3264313ab66655990e3a0.php.

Error Details

ParseError
PHP 8.2.8
10.21.0
syntax error, unexpected integer "1"
storage / framework / views / 362bf8caa4c3264313ab66655990e3a0.php : 28

362bf8caa4c3264313ab66655990e3a0.php file:

<?php

use Livewire\Volt\Actions;
use Livewire\Volt\CompileContext;
use Livewire\Volt\Contracts\Compiled;
use Livewire\Volt\Component;

new class extends Component implements Livewire\Volt\Contracts\FunctionalComponent
{
    public static CompileContext $__context;

    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

    public function mount()
    {
        (new Actions\InitializeState)->execute(static::$__context, $this, get_defined_vars());

        (new Actions\CallHook('mount'))->execute(static::$__context, $this, get_defined_vars());
    }

    public function getListeners()
    {
        $arguments = [static::$__context, $this, func_get_args()];

        return (new Actions\ResolveListeners)->execute(...$arguments);
    }

    public function 1Handler($id) 
    {
        $arguments = [static::$__context, $this, func_get_args()];

        return (new Actions\CallListener('1'))->execute(...$arguments);
    }

};

View Code Causing Error

<?php

use function Livewire\Volt\{state};
use function Livewire\Volt\{on};

on('shipment-selected', function ($id) {
    //...
});

?>

Steps To Reproduce

  1. Create a Laravel Volt component as per the provided sample code.
  2. Try to execute the application.
  3. Observe the ParseError.
nunomaduro commented 1 year ago

At the moment, on function should be used like so:

on(['eventName' => function () {
    //
}]);

Feel free to make a PR improving this.