johnsmith153 Posted July 14, 2010 Share Posted July 14, 2010 Why does this not work (of course if I change the line I have commented then it will)? I am trying to see how I would do something like this. <?php class ClassName { var $var = "hello"; public function methodName($class, $method) { $class::$method($this->var); //Class2::anotherMethod($this->var); } } class Class2 { static function anotherMethod($val) { echo "You said: ".$val; } } $newClass = new ClassName(); $newClass->methodName("Class2", "anotherMethod"); ?> Quote Link to comment Share on other sites More sharing options...
ldb358 Posted July 14, 2010 Share Posted July 14, 2010 what version of php are you using when i run it on 5.3 it works but if i would have to guess i would say your on an older version of php because if you look here http://php.net/manual/en/language.oop5.static.php it says that the first method of calling a static function was added in 5.3 Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 14, 2010 Share Posted July 14, 2010 what version of php are you using when i run it on 5.3 it works but if i would have to guess i would say your on an older version of php because if you look here http://php.net/manual/en/language.oop5.static.php it says that the first method of calling a static function was added in 5.3 Yes, use this: call_user_func(array($class, $method), $this->var); Quote Link to comment 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.