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"); ?> Link to comment https://forums.phpfreaks.com/topic/207731-oop-why-does-this-not-work/ 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 Link to comment https://forums.phpfreaks.com/topic/207731-oop-why-does-this-not-work/#findComment-1085949 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); Link to comment https://forums.phpfreaks.com/topic/207731-oop-why-does-this-not-work/#findComment-1085981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.