Skip to content

The moduleRoute helper function throws an error #2780

@zachgarwood

Description

@zachgarwood

Description

When the moduleRoute helper function is passed a $parameters with an int or string value, it throws an error, despite the function signature specifying those data types:

function moduleRoute(
    string $moduleName,
    ?string $prefix = null,
    string $action = '',
    array|int|string $parameters = [],
    bool $absolute = true
): string 

Steps to reproduce

vagrant@homestead:~/website$ php artisan tinker
Psy Shell v0.12.12 (PHP 8.2.28 — cli) by Justin Hileman
> moduleRoute('some_module', parameters: 123);

   TypeError  array_merge(): Argument #2 must be of type array, int given.

> moduleRoute('some_module', parameters: 'string');

   TypeError  array_merge(): Argument #2 must be of type array, string given.

Expected result

I expect moduleRoute to construct the url using a scalar $parameters as the first route parameter.

Actual result

The helper function throws an error due to a scalar value being passed to array_merge on lines https://github.com/area17/twill/blob/3.x/src/Helpers/routes_helpers.php#L21 and https://github.com/area17/twill/blob/3.x/src/Helpers/routes_helpers.php#L23:

TypeError  array_merge(): Argument #2 must be of type array, int given.

OR

TypeError  array_merge(): Argument #2 must be of type array, string given.

Versions

Twill version: 3.5.2
Laravel version: 11.46.0
PHP version: 8.2.28

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