diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index 0db5ebc1ddc2..0b1ba6b642d5 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -519,10 +519,17 @@ private function checkUriForMethod(string $method): void return; } - if (! in_array($method, get_class_methods($this->controller), true)) { - throw new PageNotFoundException( - '"' . $this->controller . '::' . $method . '()" is not found.' - ); + // If `getSomeMethod()` exists, only `controller/some-method` should be + // accessible. But if a visitor navigates to `controller/somemethod`, + // `getSomemethod()` will be checked, and method_exists() will return true. + if (method_exists($this->controller, $method)) { + // We do not permit `controller/somemethod`, so check the exact method + // name. + if (! in_array($method, get_class_methods($this->controller), true)) { + throw new PageNotFoundException( + '"' . $this->controller . '::' . $method . '()" is not found.' + ); + } } }