Trying to dynamically load a class:
require_once(PATH_MODULES."/{$module}/{$module}_admin.php");
$admin_class = $module."Admin";
return $admin_class::get_admin($module);
Produces this error on older versions of PHP:
Parse error: syntax error, unexpected
T_PAAMAYIM_NEKUDOTAYIM in
/home/user/public_html/folder/path/admin/filename.php on line 91
How can I change this code to work for older versions of PHP?
The problem as you probably expected, is that you cannot use dynamic class-names in PHP < 5.3. That's why the ::
is unexpected after the variable.
I don't see any way to go around this. You're not allowed to do this:
$admin_class::get_admin($module);
If this part is always the same:
$admin_class = $module."Admin";
return $admin_class::get_admin($module);
You could (and this is a hack!) add these strings to that module with the module name filled in ofcourse. Or make a separate file for that?
So for module "yourModule"
you add to the "/yourModule/yourModule_admin.php"
file these lines:
$admin_class = "yourModuleAdmin";
return yourModuleAdmin::get_admin($module);
Or add a separate file that you call yourModule_admin.olderversions.php
Not too pretty, I agree.
In PHP <5.3 you can use call_user_func
:
return call_user_func(array($admin_class, 'get_admin'), $module);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With