Hello,
Calling a function on a repetitive basis is simple enough using something like:
Gtk::timeout_add(200, 'subtract'); //call subtract() 5 times per second
However, how would I call subtract() if it is within a class? Example:
<?php
class CoolClass {
private $clickInt = 0;
function subtract() {
$this->clickInt--;
return true;
}
}
/* //I don't want to call the class function like this, or do I need to?
function subtract() {
global $coolClassInstance;
$coolClassInstance->subtract();
return true;
}
*/
$coolClassInstance = new CoolClass();
$timeoutID = Gtk::timeout_add(200, 'subtract'); //how to call $coolClassInstance->subtract()?
Gtk::main();
?>
Thanks much for the help :)
with an array
You use an array to pass the reference of the class, and the name of the method to call. PHP-GTK takes care of the rest.
<?php$timeoutID = Gtk::timeout_add(200, array($coolClassInstance, 'subtract'));
?>
Thank you much for the
Thank you much for the clarification. It works great! Also thank you "Fosfor" and you on the #php-gtk irc chat channel for initial discussion on this topic.