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? 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). 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 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? 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 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
Archived
This topic is now archived and is closed to further replies.