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?

2
  • 1
    It is very clear.. your method is called ConnectUser and your action is only Connect Commented Oct 21, 2016 at 13:30
  • It was a mistake when I copy-pasted my code. :) Commented Oct 23, 2016 at 10:37

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.