Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Jun 11, 2024 · 3 comments · Fixed by #8957
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@mktsai
Copy link

mktsai commented Jun 11, 2024

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

@mktsai mktsai added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 11, 2024
@samsonasik
Copy link
Member

I can't reproduce, tried with fresh install:

composer create-project codeigniter4/appstarter ci-news

then, add into app/Config/Routes.php

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

then, add Home::notfound() method:

+    public function notfound(): string
+    {
+        return 'not found';
+    }

then, open /404, I got not found string:

Screenshot 2024-06-11 at 17 28 16

Please try latest version, or provide test case if the issue persist. Thank you.

@kenjis
Copy link
Member

kenjis commented Jun 12, 2024

I have confirmed this error.

$ composer create-project codeigniter4/appstarter ci452
--- 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');
$ 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 
...

@kenjis
Copy link
Member

kenjis commented Jun 12, 2024

@mktsai Check #8957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants