I have created delete.php page that will accept class name and id as following:
if(isset($_GET['id']) && is_numeric(trim($_GET['id'])) ) {
$id = $_GET['id'];
}
else{
redirect_to($back);
}
if(isset($_GET['cls']) && class_exists($_GET['cls']) ) {
$class = $_GET['cls'];
}
else {
redirect_to($back);
}
Then I will create an object and call its delete method:
$object = $class::find_by_id($id);
$object->delete();
It is working fine on my localhost(wamp server). However, when I uploaded it on my host (php 5.2) it is giving me this error on line where I called static function $class::find_by_id($id): Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM. How can I solve this problem?
Chances are you're dealing with two different versions of PHP. WAMP ships with 5.3 where $class::find_by_id($id)
is allowed, on the other hand PHP 5.2 does not like it.
Try this instead:
$object = call_user_func(array($class,'find_by_id'),$id);
If that doesn't work (and I don't see why it wouldn't), you can always use eval (even though eval is bad):
eval("\$o=$f::find_by_id(\$id);");
Of course, the best solution is to upgrade to PHP >= 5.3 on your server, but you might not control that.
I have created delete.php page that will accept class name and id as following:
if(isset($_GET['id']) && is_numeric(trim($_GET['id'])) ) {
$id = $_GET['id'];
}
else{
redirect_to($back);
}
if(isset($_GET['cls']) && class_exists($_GET['cls']) ) {
$class = $_GET['cls'];
}
else {
redirect_to($back);
}
Then I will create an object and call its delete method:
$object = $class::find_by_id($id);
$object->delete();
It is working fine on my localhost(wamp server). However, when I uploaded it on my host (php 5.2) it is giving me this error on line where I called static function $class::find_by_id($id): Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM. How can I solve this problem?
Chances are you're dealing with two different versions of PHP. WAMP ships with 5.3 where $class::find_by_id($id)
is allowed, on the other hand PHP 5.2 does not like it.
Try this instead:
$object = call_user_func(array($class,'find_by_id'),$id);
If that doesn't work (and I don't see why it wouldn't), you can always use eval (even though eval is bad):
eval("\$o=$f::find_by_id(\$id);");
Of course, the best solution is to upgrade to PHP >= 5.3 on your server, but you might not control that.
0 commentaires:
Enregistrer un commentaire