MyBB Community Forums

Full Version: $plugins->add_hook() should accept closures
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
The fact that you can't do this has always bugged me.

$plugins->add_hook('some_hook', function() {
	do_something();
});

In an age where pretty much every host has PHP 5.3, I don't see why not.
Whats wrong with this?

$plugins->add_hook('some_hook', 'some_function');

function some_function () {
    do_something();
};
It's unnecessary.
And how would you use $plugins->remove_hook('some_hook', 'some_function') with closures? Undecided
You wouldn't stefan. I'd like to see Closures supported too though if it's at all possible.
As long MyBB supports PHP 5.2 it is quite impossible...
(2013-04-17, 07:52 AM)StefanT Wrote: [ -> ]And how would you use $plugins->remove_hook('some_hook', 'some_function') with closures? Undecided

In no way trying to incite an argument, but I'd like to hear the answer to that question as well . . . from a purely academic aspect.
You could probably use create_function()
(2013-04-17, 07:52 AM)StefanT Wrote: [ -> ]And how would you use $plugins->remove_hook('some_hook', 'some_function') with closures? Undecided

I didn't know that existed, good point I guess. Maybe another parameter to use as a "key"?

(2013-04-17, 09:15 AM)StefanT Wrote: [ -> ]As long MyBB supports PHP 5.2 it is quite impossible...

Who still uses 5.2?
Cheap/free hosts - which unfortunately makes up a fairly large proportion of our user base I believe. I've asked in the past about upping the minimum requirements to 5.3+ and was told we'd need to check the installation stats.
Pages: 1 2