Valect Posted November 11, 2007 Share Posted November 11, 2007 I've been trying to pass a function name to a variable to store it and run it later.. here's a snippet: $this->timer(1,"ping",$this->action->ping(),REPEAT); Not putting "$this->action->ping()" in quotes runs it, however putting it in quotes results in the error: Catchable fatal error: Object of class actions could not be converted to string... function timer($wait,$name,$what,$repeat) { $this->holder['timer'][$name]['runtime'] = time() + $wait; $this->holder['timer'][$name]['interval'] = $wait; $this->holder['timer'][$name]['execTimer'] = $what; $this->holder['timer'][$name]['repeat'] = $repeat } Later in the script is the line to run the function... $this->holder['timer'][$name]['execTimer']; I've tried serizlization and some other methods.. I think I'm just going about this all wrong. Any ideas? Link to comment https://forums.phpfreaks.com/topic/76800-solved-assigning-function-to-variable/ Share on other sites More sharing options...
kratsg Posted November 11, 2007 Share Posted November 11, 2007 Why do you have $this->action->ping()? What is the 'action' part of it? If you're calling it within the same class, you just need $this->ping() Link to comment https://forums.phpfreaks.com/topic/76800-solved-assigning-function-to-variable/#findComment-388834 Share on other sites More sharing options...
Valect Posted November 11, 2007 Author Share Posted November 11, 2007 it's another class... $this->action = new actions(); Just the way I set it up, not really relevant to what I'm trying to do Link to comment https://forums.phpfreaks.com/topic/76800-solved-assigning-function-to-variable/#findComment-388839 Share on other sites More sharing options...
Valect Posted November 11, 2007 Author Share Posted November 11, 2007 Any other ideas? I'm really at a loss here. Link to comment https://forums.phpfreaks.com/topic/76800-solved-assigning-function-to-variable/#findComment-388984 Share on other sites More sharing options...
Valect Posted November 11, 2007 Author Share Posted November 11, 2007 I solved this with eval("$".$this->holder['timer'][$name]['execTimer'].";"); and by setting it with $this->timer(1,"ping",this->action->ping(),REPEAT); Took me a good 6 hours to figure out, hope someone else benefits from this >.< Link to comment https://forums.phpfreaks.com/topic/76800-solved-assigning-function-to-variable/#findComment-389000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.