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!
Ideas Centre
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: PHP7 and the preg_replace problem

Post by AmigoJack »

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.
You do not have the required permissions to view the files attached to this post.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18409
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón

Re: PHP7 and the preg_replace problem

Post by DavidIQ »

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: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: PHP7 and the preg_replace problem

Post by AmigoJack »

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 problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Tomba
Registered User
Posts: 143
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote

Re: PHP7 and the preg_replace problem

Post by Tomba »

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: 2116
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: PHP7 and the preg_replace problem

Post by Ger »

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.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

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

-Don't PM me for support-
User avatar
Tomba
Registered User
Posts: 143
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote

Re: PHP7 and the preg_replace problem

Post by Tomba »

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.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28851
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: PHP7 and the preg_replace problem

Post by Paul »

3.2RC1 is already compatible with php7 :)
User avatar
Tomba
Registered User
Posts: 143
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote

Re: PHP7 and the preg_replace problem

Post by Tomba »

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: 18409
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón

Re: PHP7 and the preg_replace problem

Post by DavidIQ »

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: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: PHP7 and the preg_replace problem

Post by AmigoJack »

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 problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 5705
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc

Re: PHP7 and the preg_replace problem

Post by Marc »

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.
User avatar
Tomba
Registered User
Posts: 143
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote

Re: PHP7 and the preg_replace problem

Post by Tomba »

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: 18409
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón

Re: PHP7 and the preg_replace problem

Post by DavidIQ »

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: 420
Joined: Tue Aug 19, 2014 2:09 pm

Re: PHP7 and the preg_replace problem

Post by WelshPaul »

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: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: PHP7 and the preg_replace problem

Post by AmigoJack »

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 problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28

Return to “phpBB Discussion”