This is a documentation for Board Game Arena: play board games online !

PHP 8 upgrade

From Board Game Arena
Revision as of 20:13, 14 April 2024 by Quietmint (talk | contribs) (Created page with "Starting December 2023, BGA is upgrading game servers from PHP 7.4 to PHP 8.2. See https://boardgamearena.com/forum/viewtopic.php?t=33940 for more information. == Current Status == BGA studio and production are both currently running in a <b>mixed environment</b>, with some servers on PHP 7 and others on PHP 8. Until this upgrade is fully completed, your game code must be compatible with both versions of PHP. You <b>cannot</b> use any PHP 8-specific features yet. The f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Starting December 2023, BGA is upgrading game servers from PHP 7.4 to PHP 8.2. See https://boardgamearena.com/forum/viewtopic.php?t=33940 for more information.

Current Status

BGA studio and production are both currently running in a mixed environment, with some servers on PHP 7 and others on PHP 8. Until this upgrade is fully completed, your game code must be compatible with both versions of PHP. You cannot use any PHP 8-specific features yet.

The following servers are currently running PHP 8.2:

  • PHP 8 gameservers in Studio: 2
  • PHP 8 gameservers in Production: 5, 7, 8, 12

How to control your game's PHP version

In studio, you can switch between PHP 7.4 and PHP 8.2 using the Managed Game page. You can also change the gameserver portion of the URL between "/1" and "/2" (although this doesn't test your game setup code). For example, https://studio.boardgamearena.com/1/nowboarding?table=575275 is PHP 7 and https://studio.boardgamearena.com/2/nowboarding?table=575275 is PHP 8.

In production, you can add the PHP8 tag using the Game Metadata Manager page. This allows (but does not guarantee) new real-time tables for your game to be created on one of the PHP 8 servers. All turn-based tables continue to run on the PHP 7 servers.

How to fix your game's code

Here are a few common scenarios that may make your game incompatible with PHP 8:

implode argument order

The signature of this function is implode(string $separator, array $array): string.

PHP 7 accepted the arguments in either order, but PHP 8 requires the string argument first and the array argument second.

See https://www.php.net/implode

Static calls to non-static methods

PHP 8 no longer allows non-static class methods to be called statically. This may affect your game if you've created a class which extends APP_GameClass and you call various BGA framework functions statically using self::.

Non-compliant example:

   class PlayerMgr extends APP_GameClass {
       public static function getMaxScore() {
           return self::getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0");
       }

See https://php.watch/versions/8.0/non-static-static-call-fatal-error