@@ -100,7 +100,7 @@ public function execute()
100
100
} else {
101
101
// If the controller is a string, parse it into a controller and method to execute
102
102
list ($ controller , $ method ) = explode ('@ ' , $ this ->controller );
103
- $ controllerClass = "Monster \\App \\Controllers \\" . $ controller ;
103
+ $ controllerClass = "Monster \\App \\Controllers \\" . $ controller ; // Make sure to escape the backslash
104
104
105
105
// Cache the value of class_exists and call_user_func_array
106
106
static $ classExists = [];
@@ -113,18 +113,23 @@ public function execute()
113
113
if ($ classExists [$ controllerClass ]) {
114
114
if (!isset ($ callUserFuncArray [$ controllerClass ])) {
115
115
$ 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
+ }
118
122
} else {
119
- $ controllerInstance ->$ method ();
123
+ http_response_code (500 );
124
+ echo "Function not found in controller " ;
120
125
}
121
126
};
122
127
}
123
128
$ controllerInstance = new $ controllerClass ;
124
129
$ callUserFuncArray [$ controllerClass ]($ controllerInstance , $ method , $ this ->params );
125
130
} else {
126
131
http_response_code (500 );
127
- echo "Internal Server Error: Controller class not found " ;
132
+ echo "Controller class not found " ;
128
133
}
129
134
}
130
135
}
0 commit comments