1

I'm writing my own MVC framework, and i need to call static function
I have routing defined in ini file like this

[someAction]
route[] = /someroute
layout = layoutname
action[] = someAction@SomeController

after matching routing im using explode() function to split action and controller

$action = explode('@', $this->_action); 
//$this->_action = someAction@SomeController

and now I wanna call

$action[1]::$action[0]();

But php thinks that I wanna call static field instead of method, can somebody tell me how to call it as method ?

4
  • 1
    Use call_user_func() Commented Aug 20, 2014 at 7:46
  • Possibly something like $a = new $action[1](); $a->$action[0](); Commented Aug 20, 2014 at 7:47
  • 1
    Have a look at forward_static_call php.net/manual/en/function.forward-static-call.php or call_user_func php.net/manual/en/function.call-user-func.php I'm sure you'd find your answer in any one of these functions. Commented Aug 20, 2014 at 7:47
  • 1
    Easier would be to switch the "controller" and the "action" so you can just call $action() eval.in/181257 Commented Aug 20, 2014 at 7:47

2 Answers 2

2

You can use call_user_func()

Try this :

call_user_func(array($action[1],$action[0]));

edit : depending of your PHP version, PeeHaa's comment is a good idea !

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

Comments

0

You can call it this way:

<?php

    list($action, $controller) = explode('@', $this->_action);
    $controller::$action();

?>

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.