1

I'm creating my own MVC framework with my own routes engine. When I call a page, my URL is like that : http://www.domain.com/lang/controller/method/

Everything is ok with this configuration but when I send parameters by POST, I want them in my function declaration. For example :
$_POST => Array ( [login] => myLogin, [pwd] => myPassword) for the function ConnectUser($login, $password).

My controller is a singleton. So, my function call is like that : \core\controller\UserController::getInstance()->ConnectUser($login, $password).

I generate my call in a string. When I do

$funcCall = $strCall . "::getInstance()->" . $_GET['action'] . "()";
forward_static_call_array($funcCall, $_POST);

I get this error :

forward_static_call_array() expects parameter 1 to be a valid callback,
class 'core\controller\UserController' does not have a method 'getInstance()->Connect()'

Do you have an idea on my problem?

Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
Vincent
  • 11
  • 2

1 Answers1

1
  1. "core\controller\UserController::getInstance()->Connect()" is not a valid callback

  2. You should use call_user_func_array() instead of forward_static_call_array() since you aren't calling static methods (and even if you were you likely aren't calling them from a context where it would matter).

  3. $_POST will not get magically mapped to the method's arguments by name. You'd have to use reflection for that. See Passing named parameters to a php function through call_user_func_array

Community
  • 1
  • 1
Shira
  • 6,392
  • 2
  • 25
  • 27