Paweł Andruszków
Paweł Andruszków

Reputation: 8403

How to call static function defined in variable?

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 ?

Upvotes: 1

Views: 87

Answers (2)

Roham Tehrani
Roham Tehrani

Reputation: 2989

You can call it this way:

<?php

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

?>

Upvotes: 0

Kevin Lab&#233;cot
Kevin Lab&#233;cot

Reputation: 1995

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 !

Upvotes: 2

Related Questions