I’m 9 to 6 Java programer but in my spare time I have little proyects in PHP.
Just wondering what do you guys think of using this class and what security considerations I might have
class Action{
var $func;
var $param;
function Action(){
$url_keys = array_keys($_GET);
$this->func = $url_keys[0];
$this->param = $_GET[$this->func];
}
function callFunction(){
$f = $this->func;
$f( $this->param );
}
}
$ajax = new Action();
$ajax-> callFunction();
I was thinking to using this including or extending another class.
http://localhost/proyect/object.php?update=1
include_once("class.Action.php");
function update($id){
//the function
}
For the record I don’t want to use a framework this proyect its to small 😛
Well first of all you should be working with php5 which has visibility keywords and some other things:
You should always pass in
$_GETIMO so your instantiation now looks like this:Now as far as what youre trying to accomplish here it is unclear. If youre trying to essentially build a routing class i think this is pretty ugly and error prone as is.
In terms of you comment about not wanting to use a framework because the project is simple/small id urge you to check out Silex or Slim micro frameworks instead of building from scratch.
For example with Silex: