PDA

View Full Version : Callbacks are nifty


filburt1
25 Jan 2006, 23:49
I finally found a way to emulate an event firing model from Java: callbacks. http://www.php.net/callback and http://www.php.net/create_function . Nowhere near as clean as Java with implementing interfaces and providing listeners, but it works:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


Now $installer->upgrade() will fire the callback function as it executes, providing status updates. Calling the callback is as simple as:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Of course, in Java, it would be more like:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


...but that would require PHP 5 at least because of the abstractifiedness needed.

Andreas
26 Jan 2006, 01:15
May I ask why you are using create_function()?

filburt1
26 Jan 2006, 02:25
To create an anonymous function rather than one publicly accessible by every other bit of code.