doddsey_65 Posted September 12, 2011 Share Posted September 12, 2011 Using this locally works fine: $html = $name::add_content($name, $html); but i get the double colon error whe using it live. $name is a name of a valid class. What could throw this error when it works locally? Quote Link to comment https://forums.phpfreaks.com/topic/246942-variable-for-class-name-and-method/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 12, 2011 Share Posted September 12, 2011 5.3.0 Changed: It's now possible to reference the class using a variable (e.g., echo $classname::constant;). The variable's value can not be a keyword (e.g., self, parent or static). Quote Link to comment https://forums.phpfreaks.com/topic/246942-variable-for-class-name-and-method/#findComment-1268212 Share on other sites More sharing options...
xyph Posted September 12, 2011 Share Posted September 12, 2011 AKA - PHP version Quote Link to comment https://forums.phpfreaks.com/topic/246942-variable-for-class-name-and-method/#findComment-1268213 Share on other sites More sharing options...
doddsey_65 Posted September 12, 2011 Author Share Posted September 12, 2011 just my luck, server uses 5.2. Is there any way I could achieve the same thing? Quote Link to comment https://forums.phpfreaks.com/topic/246942-variable-for-class-name-and-method/#findComment-1268215 Share on other sites More sharing options...
xyph Posted September 12, 2011 Share Posted September 12, 2011 <?php class myClass { static function printWords( $w1, $w2 ) { echo $w1.' '.$w2; } } $name = 'myClass'; call_user_func_array( array($name,'printWords'), array('hello','world') ); ?> http://php.net/manual/en/function.call-user-func-array.php Quote Link to comment https://forums.phpfreaks.com/topic/246942-variable-for-class-name-and-method/#findComment-1268218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.