I want to make a simple page in PHP which read from URL a specified function with relative parameters.
My URL is like www.mysite.com/Api.php?function=sendMail&name=AA000AA
I get the URL using $_SERVER['REQUEST_URI'] and pass the result to a Class i wrote which has the following construct
public function __construct($uri = '')
Everything works fine until I add the parameters with ampersand where I get the following error
Fatal error: Uncaught Error: Function name must be a string in /data/web/Api.php:36 Stack trace: #0 /data/web/Api.php(71): ApiAction->__construct('/app/Api.php?fu...')
But after a check with var_dump i got this
string(43) "/Api.php?function=sendMail&name=AA000AA"
Which tells me is a string. I've tried to cast it but it keep giving me the same error.
The class I'm calling has the following code
class ApiAction{
protected $link;
public function __construct($uri){
$request = str_replace("/Api.php?", "", $uri);
$parameters = explode("&", $request);
$command = array();
foreach ($parameters as $value) {
$tmp = explode("=", $value);
$command[$tmp[0]] = (string)$tmp[1];
}
$result = '';
}
But it get stuck in this error when I create a new instance of this class with
new ApiAction($_SERVER['REQUEST_URI']);
But, as mentioned before, it work perfectly before I add parameters with ampersand, I.E.
www.mysite.com/Api.php?function=sendMail
Works without any problems
$class->$method()or such. Can we see line 36 of Api.php?