PHP7 and the preg_replace problem

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Get Involved
User avatar
AmigoJack
Registered User
Posts: 4992
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP7 and the preg_replace problem

Post by AmigoJack » Tue Aug 30, 2016 3:20 pm

Not sure why you haven't attached it to your post, as that'd be the most reliable thing when people will read this in 1-2 years and your host might have vanished.
phpbb_preg_replace_callback.png
beatme101 wrote:the 5 line replacement
The error clearly states that /e is not supported anymore. So you have to ask yourself where it is used in the first place. What does "my" code change? You see nowhere turning an /e into /. Since the regexp in any preg_replace*() is always passed as the first argument you should ask "where is $preg populated?" (alternatively: just print out its content and you'll understand the error message much better). And then you would discover it comes thru class bbcode::bbcode_cache_init() (starting with line 211): every time the modifier e is used you have to delete it:

Code: Select all

#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise
#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise
#\[list=([^\[]+):$uid\]#e
must become

Code: Select all

#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#is
#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#is
#\[list=([^\[]+):$uid\]#
Yes, to achieve what you want requires you to understand the problem in general, but also what regular expression modifiers are.
beatme101 wrote:The line 494 replacement works.
I just guess you mean line 488 in an untouched file, as I can't have a clue on how your modified file may look like.


My whole point was: for the development team it should have been a rather easy task, just as it'd be for me (speak: something achievable within days or even hours, not weeks). Hence I have no clue why it needed to wait until 3.2.
The worst thing about censorship is ███████████

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16543
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: PHP7 and the preg_replace problem

Post by DavidIQ » Tue Aug 30, 2016 3:31 pm

AmigoJack wrote: My whole point was: for the development team it should have been a rather easy task, just as it'd be for me (speak: something achievable within days or even hours, not weeks). Hence I have no clue why it needed to wait until 3.2.
3.2 was scheduled to be out already so the plan to scrap PHP7 support in 3.1 and give it full support in 3.2 was a very sound one, something I'm sure you're well aware of and probably agreed with in principle. Assuming you're a developer I'm sure you're familiar with how development can fall behind for various reasons. This project has additional ways in which development can fall behind since it's handled by volunteers.

We can expect 3.2 to be out in the foreseeable future though so hopefully this can be put to rest once and for all.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
AmigoJack
Registered User
Posts: 4992
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP7 and the preg_replace problem

Post by AmigoJack » Tue Sep 13, 2016 6:10 pm

nicofuma wrote:Otherwise, 3.2 should be released at the end of the year, around November. This version should already be compatible with php7
Both things aren't true: 3.2 still has not been released, and the RC1 is not PHP7 compatible either (custom BBCodes still require /e).
The worst thing about censorship is ███████████

Tomba
Registered User
Posts: 130
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: PHP7 and the preg_replace problem

Post by Tomba » Tue Nov 01, 2016 1:15 pm

I'm sorry if I'm throwing oil on the fire, but I'm amazed that the phpBB team keeps on using 3.2 in defence of the lack of PHP7 compability.

Being a software developer, I am indeed very aware that planning can slip, but re-planning is part of the process, and this was missed completely here. The result is now that PHP7 is mainstream since Dec 3, 2015, so for 11 months now, there is no phpBB release available that is compatible with the main version of PHP.
In essence, I've got a project with 13 dependencies, and all are compatible, except phpBB.

Anyway, assuming the phpBB team sticks to its stance, I'm wondering if anyone has patched the code?

User avatar
Ger
Registered User
Posts: 1151
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: PHP7 and the preg_replace problem

Post by Ger » Tue Nov 01, 2016 1:35 pm

Well, being a software developer like you say you are, you are quite welcome to provide a patch to make phpBB 3.2 3.1 compatible with PHP 7, including all the old content.

I stand corrected :)
Last edited by Ger on Wed Nov 02, 2016 7:39 am, edited 1 time in total.
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

Like my work? Buy me a coffee to keep it coming. :ugeek:

Tomba
Registered User
Posts: 130
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: PHP7 and the preg_replace problem

Post by Tomba » Tue Nov 01, 2016 6:18 pm

Indeed, I intend to, because I must fix it anyway. But I don't like doing duplicate work, so I hope someone else who went through the same could share their efforts.

I'd be happy to compose a pull request if necessary.

User avatar
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 23720
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: PHP7 and the preg_replace problem

Post by Paul » Tue Nov 01, 2016 7:12 pm

3.2RC1 is already compatible with php7 :)
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Tomba
Registered User
Posts: 130
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: PHP7 and the preg_replace problem

Post by Tomba » Tue Nov 01, 2016 10:00 pm

For those interested to fix their phpbb 3.1.x versions, the commits done on https://tracker.phpbb.com/browse/PHPBB3-13832 are of interest to merge back.

In fact, why not merge them back into 3.1.11 anyway? ;)

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16543
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: PHP7 and the preg_replace problem

Post by DavidIQ » Tue Nov 01, 2016 11:17 pm

Tomba wrote:In fact, why not merge them back into 3.1.11 anyway? ;)
You don't really want us to rehash and repeat all of the reasons why not right? ;)
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
AmigoJack
Registered User
Posts: 4992
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP7 and the preg_replace problem

Post by AmigoJack » Wed Nov 02, 2016 8:21 am

No, as that doesn't fix custom BBCodes. Like I commented in PHPBB3-13857 parsing the PHP code stored in the database would be one way to solve this. Currently I do this for 1+ month on a 3.0.14 installation and it works without any flaw.
The worst thing about censorship is ███████████

User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 5234
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc
Contact:

Re: PHP7 and the preg_replace problem

Post by Marc » Wed Nov 02, 2016 4:15 pm

Please take a look at the latest comments in that ticket. I don't think that the BBCode first pass is used for custom bbcodes in 3.2 anymore and therefore the /e modifier is also no longer used.
Quickedit for phpBB 3.1
I'm available for custom work - just send me a PM for a quote.

Tomba
Registered User
Posts: 130
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: PHP7 and the preg_replace problem

Post by Tomba » Wed Nov 02, 2016 7:24 pm

DavidIQ wrote:
Tomba wrote:In fact, why not merge them back into 3.1.11 anyway? ;)
You don't really want us to rehash and repeat all of the reasons why not right? ;)
Actually... :D
But joking aside, seeing these commits, I assume they are covered by automatic tests, and would hence be fairly straightforward to merge. I really think in the future, phpBB needs to try to always have a release available that is compatible with the latest PHP version.
Marc wrote:Please take a look at the latest comments in that ticket. I don't think that the BBCode first pass is used for custom bbcodes in 3.2 anymore and therefore the /e modifier is also no longer used.
In noticed, but I'm trying to achieve 3.1 compatibility on PHP7 in the coming weeks, unless you can release 3.2 tomorrow ;)

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16543
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: PHP7 and the preg_replace problem

Post by DavidIQ » Wed Nov 02, 2016 7:45 pm

Tomba wrote:But joking aside, seeing these commits, I assume they are covered by automatic tests, and would hence be fairly straightforward to merge. I really think in the future, phpBB needs to try to always have a release available that is compatible with the latest PHP version.
Ok let's say we did that and PHP 99 rolled around and completely got rid of preg_replace with no backwards compatibility with the previous PHP version and in it's place is replace_preg. If we followed your suggestion we would go and replace preg_replace with the new replace_preg function throughout current code because, why not...there's a new PHP version and everyone needs to be on it already according to us. Well we've just broken a lot of people's boards and most everyone's unhappy. Adding code throughout to check PHP versions would be pretty ugly and messy and not likely something we'd ever want to do.

Obviously this isn't what has happened in PHP 7 and the PHP developers probably wouldn't do such a thing without ample notice, but changing an already released version to comform to a new underlying platform is almost never a good idea and is why new major versions are released instead by most software vendors I've seen. Plus very few hosting providers are going to all of a sudden dump PHP 5 in place of 7 anytime soon, that is if they want to keep their customers, so this hasn't reached a critical point where we have no choice but to go backwards and into 3.1 to get core things changed for PHP 7 support.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
WelshPaul
Registered User
Posts: 201
Joined: Tue Aug 19, 2014 2:09 pm

Re: PHP7 and the preg_replace problem

Post by WelshPaul » Mon Nov 07, 2016 2:39 pm

Dion has published a guide on how to make phpBB 3.1.x compatible with PHP 7.
Its straight forward. It's not even a guide its a file replacement...

http://forum.dion-designs.com/t9150/mak ... th-php-70/

Once that is done then you can enable PHP 7 on your server.

User avatar
AmigoJack
Registered User
Posts: 4992
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP7 and the preg_replace problem

Post by AmigoJack » Mon Nov 07, 2016 3:22 pm

WelshPaul wrote:Dion has published
a file replacement
Let's see...

Code: Select all

// eval() sucks, but we must use preg_replace_callback() to support
// PHP 7.0, and custom BBcode replacement function is stored as a string
$this->message = preg_replace_callback($regexp, function($matches) use($replacement) {eval('$str=' . $replacement[1]); return $str;}, $this->message);
So PHP7 disables /e, but Dion fixes this by using eval()? That's what e was standing for all along. Good luck to those environments where this function is disabled.

Code: Select all

// convert emojis to HTML entities
$result = preg_replace_callback('/([\x{1f000}-\x{1ffff}])/u', function($matches) {
    return strtolower('&#x' . dechex(substr(mb_convert_encoding($matches[1], 'HTML-ENTITIES', 'UTF-8'), 2, -1)) . ';');
}, $result);
Do not store characters, but instead let's go back using outdated approaches from times when encoding problems were avoided the very same way. (Also inflates byte usage of such characters from 4 to 9.)


No, Dion doesn't fix - he only kludges. It's like avoiding validator errors by splitting up literals: just because it's now supported doesn't mean it's good code now as well.
The worst thing about censorship is ███████████

Post Reply

Return to “phpBB Discussion”

Who is online

Users browsing this forum: kullboys and 24 guests

cron