Converting from PHP 7 to 8
Posted: Sun Oct 24, 2021 10:44 am
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:
Replace:
3. Find all instances of classes with a function with the same name as the class. They must be changed to __construct:
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!
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*\)Code: Select all
foreach \($3 as $1 => $2\)Code: Select all
(?ms)class\s+(?<CLASS>\w+)\s+\{.+\g{CLASS}\(There weren't enough of them to bother automating the replacement, so I'll leave that as a challenge for the reader!