Skip to content

Commit fdc18a8

Browse files
authored
fix
1 parent cb0c465 commit fdc18a8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

App/Core.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function execute()
100100
} else {
101101
// If the controller is a string, parse it into a controller and method to execute
102102
list($controller, $method) = explode('@', $this->controller);
103-
$controllerClass = "Monster\\App\\Controllers\\" . $controller;
103+
$controllerClass = "Monster\\App\\Controllers\\" . $controller; // Make sure to escape the backslash
104104

105105
// Cache the value of class_exists and call_user_func_array
106106
static $classExists = [];
@@ -113,18 +113,23 @@ public function execute()
113113
if ($classExists[$controllerClass]) {
114114
if (!isset($callUserFuncArray[$controllerClass])) {
115115
$callUserFuncArray[$controllerClass] = function ($controllerInstance, $method, $params) {
116-
if ($params) {
117-
$controllerInstance->$method(...$params);
116+
if (method_exists($controllerInstance, $method)) { // Check if the method exists in the controller class
117+
if ($params) {
118+
$controllerInstance->$method(...$params);
119+
} else {
120+
$controllerInstance->$method();
121+
}
118122
} else {
119-
$controllerInstance->$method();
123+
http_response_code(500);
124+
echo "Function not found in controller";
120125
}
121126
};
122127
}
123128
$controllerInstance = new $controllerClass;
124129
$callUserFuncArray[$controllerClass]($controllerInstance, $method, $this->params);
125130
} else {
126131
http_response_code(500);
127-
echo "Internal Server Error: Controller class not found";
132+
echo "Controller class not found";
128133
}
129134
}
130135
}

0 commit comments

Comments
 (0)