Converting from PHP 7 to 8

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
bbadmin
Site Admin
Posts: 855
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Converting from PHP 7 to 8

Post by bbadmin »

There are a few breaking changes in PHP 8, so I used TextPad and WildEdit to help with some of them.

1. Rename all instances of: $match to $matches.

2. Change: while (list($key, $val) = each($arr));
to: foreach ($arr as $key => $val);

Find:

Code: Select all

while\s*\(\s*list\((\$\w+),\s*(\$\w+)\s*\)\s*=\s*@*each\(([^)]+\))\s*\)
Replace:

Code: Select all

foreach \($3 as $1 => $2\)
3. Find all instances of classes with a function with the same name as the class. They must be changed to __construct:

Code: Select all

(?ms)class\s+(?<CLASS>\w+)\s+\{.+\g{CLASS}\(
The "(?ms)" part enables searches to span line boundaries.

There weren't enough of them to bother automating the replacement, so I'll leave that as a challenge for the reader!
User avatar
AmigoJack
Posts: 515
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Looks like PHP7 was skipped entirely. There are sure more breaking changes, i.e.:
  • preg_replace() with the /e modifier must be rewritten to preg_replace_callback(). If I remember correctly phpBB2 is using ereg_*() which was deprecated ages ago anyway.
  • Variable variable names such as $$var now have a different precedence, so it should all made be clear with curly brackets, i.e. ${$var}
  • MySQL must become MySQLi
  • All the *magic_quotes_runtime*() crap is gone
Better read both migrations: to 7.0 and to 8.0:
Post Reply