MyBB Community Forums

Full Version: Closure support for plugins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I wanted to make this thread o gather feedback from other plugin developers on this pull request: https://github.com/mybb/mybb/pull/171

Stefan is obviously against it, but what do others think? I personally would like to think that MyBB can help drive adoption of more modern PHP versions (even if 5.3 is actually End of Life too...).

On a side note, had I not been used to MyBB and was new to developing the platform, your response would likely have lead me to never again contributing Stefan. Just saying.
I am not fully understanding the use of Closures, so i can not comment to that.

We had a discussion several month ago about min requirements and we decided upon 5.2 then, though I am starting to think 5.3.11 or later would be better.
(2013-12-06, 07:56 PM)Euan T Wrote: [ -> ]On a side note, had I not been used to MyBB and was new to developing the platform, your response would likely have lead me to never again contributing Stefan. Just saying.
If I can not express my opinon, I should probably leave...
I'm not saying that Stefan, I just think the way that pull requests/feature suggestions are handled needs better planning and discussion. Perhaps the GitHub plugin could be expanded to post pull requests to the forum so they have more public input and exposure? I'm not sure how much access GitHub's API allows for that type of thing.

@pavemen: The patch allows plugins to be written similar to the following (from the hello plugin):

$plugins->add_hook("pre_output_page", function($page) {
    $page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
    return $page;
});

This makes the creation of simple plugins faster, and also means that you have one less file to require (were the whole plugin written using closures that is). Obviously the downside is that Closures are a PHP 5.3 feature as Stefan mentioned on GitHub, but perhaps we can work out a way of adding a minimum requirements section to the mods site or something?
I though we could do that already. did not realize it was a 5.3+ thing.
(2013-12-06, 09:55 PM)Euan T Wrote: [ -> ]I'm not saying that Stefan, I just think the way that pull requests/feature suggestions are handled needs better planning and discussion. Perhaps the GitHub plugin could be expanded to post pull requests to the forum so they have more public input and exposure? I'm not sure how much access GitHub's API allows for that type of thing.

@pavemen: The patch allows plugins to be written similar to the following (from the hello plugin):

$plugins->add_hook("pre_output_page", function($page) {
    $page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
    return $page;
});

This makes the creation of simple plugins faster, and also means that you have one less file to require (were the whole plugin written using closures that is). Obviously the downside is that Closures are a PHP 5.3 feature as Stefan mentioned on GitHub, but perhaps we can work out a way of adding a minimum requirements section to the mods site or something?

While I understand the downside of it being a PHP5.3 required feature and how some (or most, have not done much research in a while. Isn't it like 40% 5.3) hosts may not support the 5.3 version, I also tend to believe any push for increasing the PHP version would be a good thing. Web Hosts should be at least using 5.3, or giving the option to do so.

Any host that still runs 5.2 is NOT a serious host, or shouldn't be considered one. I tend to think that 5.2 hosts won't last long if they continue to be late on updates (2+ years late), and in a sense, won't be an issue in the long run.

So if web hosts should be using 5.3, and if 5.3 should generically be used, why not push for MyBB users to use 5.3

Drupal v8 has a 5.4 requirement, while Drupal v7 has a 5.2.5 requirement.

They've done it. Is there a reason we cannot?

My Opinion has always been when some hosts (or most, see above) won't take the responsibility to push the switch to higher versions of PHP (or other software), then it should be scripts/software developer's responsibility to do so.

Kind of like a Civic Responsibility. Not a obligation, but we should.

Just my two cents I guess.

(2013-12-06, 10:11 PM)pavemen Wrote: [ -> ]I though we could do that already. did not realize it was a 5.3+ thing.

It utilizes the Closure class

http://php.net/manual/en/class.closure.php

which has a 5.3 requirement.

(2013-12-06, 09:55 PM)Euan T Wrote: [ -> ]I'm not saying that Stefan, I just think the way that pull requests/feature suggestions are handled needs better planning and discussion. Perhaps the GitHub plugin could be expanded to post pull requests to the forum so they have more public input and exposure? I'm not sure how much access GitHub's API allows for that type of thing.

I'd love this if it was implemented. Even if it just posted a link to the specific commit.

http://developer.github.com/v3/repos/commits/
(2013-12-06, 09:55 PM)Euan T Wrote: [ -> ]
$plugins->add_hook("pre_output_page", function($page) {
    $page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
    return $page;
});

This makes the creation of simple plugins faster, and also means that you have one less file to require.
All what I see is that it saves ~1 line of code. Yes, PHP 5.2 is EOL but I don't see why we shouldn't support it because of such a small change.
There are a lot of scripts not supporting PHP 5.3 which is why some hosts haven't switched to newer PHP version.
(2013-12-07, 11:00 AM)StefanT Wrote: [ -> ]Yes, PHP 5.2 is EOL but I don't see why we shouldn't support it because of such a small change.
There are a lot of scripts not supporting PHP 5.3 which is why some hosts haven't switched to newer PHP version.

Personally I think it is a vicious cycle, hosts stick to outdated PHP versions because people use scripts that need them because the people who make the scripts continue to support them. PHP 5.2 has been EOL for three years, hosts shouldn't offer it anymore and as a result I don't see why MyBB needs to provide support for it.
(2013-12-07, 11:00 AM)StefanT Wrote: [ -> ]
(2013-12-06, 09:55 PM)Euan T Wrote: [ -> ]
$plugins->add_hook("pre_output_page", function($page) {
    $page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
    return $page;
});

This makes the creation of simple plugins faster, and also means that you have one less file to require.
All what I see is that it saves ~1 line of code. Yes, PHP 5.2 is EOL but I don't see why we shouldn't support it because of such a small change.
There are a lot of scripts not supporting PHP 5.3 which is why some hosts haven't switched to newer PHP version.

And a file include. Meaning it uses less memory as less files are required by the system.

It's a nice option to have, even if it isn't a major feature.
(2013-12-07, 03:54 PM)Euan T Wrote: [ -> ]And a file include.
How? The function definitions are normally in the same file?
Pages: 1 2