Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in system\Router\DefinedRouteCollector.php on line 49
### 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_


Discussion:
I can't reproduce, tried with fresh install:

```
composer create-project codeigniter4/appstarter ci-news
```

then, add into `app/Config/Routes.php`

```diff
+$routes->get('/404', 'Home::notfound');
```

then, add `Home::notfound()` method:

```diff
+    public function notfound(): string
+    {
+        return 'not found';
+    }
```

then, open `/404`, I got `not found` string:

![Screenshot 2024-06-11 at 17 28 16](https://github.com/codeigniter4/CodeIgniter4/assets/459648/ea41fffc-89f3-49ee-95a1-04dba7b860a7)

Please try latest version, or provide test case if the issue persist. Thank you.
I have confirmed this error.

```console
$ composer create-project codeigniter4/appstarter ci452
```
```diff
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -5,4 +5,4 @@ use CodeIgniter\Router\RouteCollection;
 /**
  * @var RouteCollection $routes
  */
-$routes->get('/', 'Home::index');
+$routes->get('/404', 'Home::index');
```
```console
$ php spark env development # This step is missing in the "Steps to Reproduce"
$ php spark serve
```
Navigate to http://localhost:8080/404
```
Displayed at 00:08:40am — PHP: 8.2.20 — CodeIgniter: 4.5.2 -- Environment: development

TypeError

CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in /Users/kenji/tmp/ci452/vendor/codeigniter4/framework/system/Router/DefinedRouteCollector.php on line 48 
...
```
@mktsai Check #8957




Patch:
diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php
index 8d4f1dc5b1b7..2452a141fa75 100644
--- a/system/Router/DefinedRouteCollector.php
+++ b/system/Router/DefinedRouteCollector.php
@@ -38,6 +38,10 @@ public function collect(): Generator
             $routes = $this->routeCollection->getRoutes($method);
 
             foreach ($routes as $route => $handler) {
+                // The route key should be a string, but it is stored as an array key,
+                // it might be an integer.
+                $route = (string) $route;
+
                 if (is_string($handler) || $handler instanceof Closure) {
                     if ($handler instanceof Closure) {
                         $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;


Test patch:
diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php
index ca10a2fd7b51..7c493c028512 100644
--- a/tests/system/Router/DefinedRouteCollectorTest.php
+++ b/tests/system/Router/DefinedRouteCollectorTest.php
@@ -50,8 +50,10 @@ public function testCollect(): void
     {
         $routes = $this->createRouteCollection();
         $routes->get('journals', 'Blogs');
+        $routes->get('100', 'Home::index');
         $routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
         $routes->get('feed', static fn () => 'A Closure route.');
+        $routes->get('200', static fn () => 'A Closure route.');
         $routes->view('about', 'pages/about');
 
         $collector = new DefinedRouteCollector($routes);
@@ -69,6 +71,12 @@ public function testCollect(): void
                 'name'    => 'journals',
                 'handler' => '\App\Controllers\Blogs',
             ],
+            [
+                'method'  => 'GET',
+                'route'   => '100',
+                'name'    => '100',
+                'handler' => '\App\Controllers\Home::index',
+            ],
             [
                 'method'  => 'GET',
                 'route'   => 'product/([0-9]+)',
@@ -81,6 +89,12 @@ public function testCollect(): void
                 'name'    => 'feed',
                 'handler' => '(Closure)',
             ],
+            [
+                'method'  => 'GET',
+                'route'   => '200',
+                'name'    => '200',
+                'handler' => '(Closure)',
+            ],
             [
                 'method'  => 'GET',
                 'route'   => 'about',