
When first starting with PHP-GTK, you may be puzzled by two specific pieces of code (or maybe three):
PHP Code:
if (!class_exists('gtk')) {
die("Gtk class not found");
}
$window->connect_simple('destroy', array('gtk', 'main_quit'));
Gtk::main();
The second line of code with the connect_simple() method is connecting a signal (event) to a "handler". However, in this case, you want the main_quit() method to be executed which, in effect, quits the active PHP-GTK application. If you don't have this line, it won't break your PHP-GTK application, but it will mean that closing the application window will not quit the application entirely - which is why this line of code is necessary. It terminates the main loop that otherwise keeps the application active. To make things as clear as possible - when an application window is destroyed (closed), the destroy signal is fired. However, the destroy signal is also emitted when any widget is destroyed. So in essence, what is happening here is the destroy signal, when emitted, will execute the main_quit() method which effectively quits the application.
However, the last line - Gtk::main() is very important to have in your PHP-GTK application. If you don't have this in your PHP-GTK application, it will appear as if your application does not open because the application is opened momentarily then quits because the Gtk::main() method hadn't been executed to keep the application active. If you're writing your PHP-GTK application fully object-oriented, you'll have the Gtk::main() loop within the constructor method. Read more on object-oriented constructors.
See the full list of tutorials in this section.