Skip to content

Bug: CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in system\Router\DefinedRouteCollector.php on line 49 #8954

Closed
@mktsai

Description

@mktsai

PHP Version

8.2

CodeIgniter4 Version

4.5.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows, Linux

Which server did you use?

apache

Database

MariaDB 10.4.28

What happened?

When I set a router path '/404' in app\Config\Routers.php

$routes->get('/404', 'Home::notfound');

The error message display are showing after I reload website.

TypeError
CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in D:\xampp\htdocs\project\vendor\codeigniter4\framework\system\Router\DefinedRouteCollector.php on line 49 

Steps to Reproduce

add $routes->get('/404', 'Home::notfound'); to app\Config\Routers.php

Expected Output

when user into '/404' url, will see the notFound page.

And I fixed it.

I add $route = is_numeric($route) ? (string)$route : $route; into system\Router\DefinedRouteCollector.php line 41.
Check if $route is numeric. If it is, convert it to a string type before use $this->routeCollection->getRoutesOptions() function.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions