This is a documentation for Board Game Arena: play board games online !
PHP 8 upgrade: Difference between revisions
No edit summary |
|||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 2: | Line 2: | ||
[[Category:Studio]] | [[Category:Studio]] | ||
Starting | Starting in 2023-12, BGA began upgrading game servers from PHP 7.4 to PHP 8.2. See https://boardgamearena.com/forum/viewtopic.php?t=33940 for more information. | ||
As of 2024-08-09, the BGA upgrade to PHP 8.2 is '''complete'''. Your game can now use PHP 8-specific features. 🎉 | |||
BGA | |||
As of 2025-10-06, the BGA upgrade to PHP 8.8 is '''complete'''. Your game can now use PHP 8.4-specific features. 🎉 | |||
== Fix your game's code == | == Fix your game's code == | ||
| Line 29: | Line 20: | ||
=== Static calls to non-static methods === | === Static calls to non-static methods === | ||
See https://php.watch/versions/8.0/non-static-static-call-fatal-error and https://www.php.net/manual/en/language.oop5.basic.php | 📖 See https://php.watch/versions/8.0/non-static-static-call-fatal-error and https://www.php.net/manual/en/language.oop5.basic.php | ||
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 <code>extends | 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 <code>extends APP_DbObject</code> and you call various BGA framework functions statically using <code>self::</code>. | ||
If possible, the simplest change is to replace <code>self::</code> with <code>$this-></code> (which refers to the current instance of your game class). This works if your function is non-static. | If possible, the simplest change is to replace <code>self::</code> with <code>$this-></code> (which refers to the current instance of your game class). This works if your function is non-static. | ||
| Line 37: | Line 28: | ||
Non-compliant example: | Non-compliant example: | ||
class NMap extends | class NMap extends APP_DbObject { | ||
public function getPossibleMoves($playerId) { | public function getPossibleMoves($playerId) { | ||
$planeHasNervous = intval(self::getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0; | $planeHasNervous = intval(self::getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0; | ||
| Line 43: | Line 34: | ||
Fix: | Fix: | ||
class NMap extends | class NMap extends APP_DbObject { | ||
public function getPossibleMoves($playerId) { | public function getPossibleMoves($playerId) { | ||
$planeHasNervous = intval($this->getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0; | $planeHasNervous = intval($this->getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0; | ||
| Line 51: | Line 42: | ||
Non-compliant example: | Non-compliant example: | ||
class PlayerMgr extends | class PlayerMgr extends APP_DbObject { | ||
public static function getMaxScore() { | public static function getMaxScore() { | ||
return self::getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0"); | return self::getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0"); | ||
| Line 64: | Line 55: | ||
self::$instance = $this; | self::$instance = $this; | ||
class PlayerMgr extends | class PlayerMgr extends APP_DbObject { | ||
public static function getMaxScore() { | public static function getMaxScore() { | ||
return hardback::$instance->getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0"); | return hardback::$instance->getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0"); | ||
} | } | ||
Latest revision as of 09:55, 6 October 2025
Starting in 2023-12, BGA began upgrading game servers from PHP 7.4 to PHP 8.2. See https://boardgamearena.com/forum/viewtopic.php?t=33940 for more information.
As of 2024-08-09, the BGA upgrade to PHP 8.2 is complete. Your game can now use PHP 8-specific features. 🎉
As of 2025-10-06, the BGA upgrade to PHP 8.8 is complete. Your game can now use PHP 8.4-specific features. 🎉
Fix your game's code
Here are a few common scenarios that may make your game incompatible with PHP 8 and how to fix them:
implode argument order
📖 See https://www.php.net/manual/en/function.implode.php
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.
Static calls to non-static methods
📖 See https://php.watch/versions/8.0/non-static-static-call-fatal-error and https://www.php.net/manual/en/language.oop5.basic.php
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_DbObject and you call various BGA framework functions statically using self::.
If possible, the simplest change is to replace self:: with $this-> (which refers to the current instance of your game class). This works if your function is non-static.
Non-compliant example:
class NMap extends APP_DbObject {
public function getPossibleMoves($playerId) {
$planeHasNervous = intval(self::getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0;
Fix:
class NMap extends APP_DbObject {
public function getPossibleMoves($playerId) {
$planeHasNervous = intval($this->getUniqueValueFromDB("SELECT COUNT(1) FROM `pax` WHERE `player_id` = $playerId AND `status` = 'SEAT' AND `vip` = 'NERVOUS'")) > 0;
Otherwise, if your own function is static and $this-> doesn't exist, you can create a static variable like $instance in your game class, populate the variable in your game's constructor, and call the BGA framework functions through this variable.
Non-compliant example:
class PlayerMgr extends APP_DbObject {
public static function getMaxScore() {
return self::getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0");
}
Fix:
class hardback extends Table {
public static $instance = null;
function __construct() {
parent::__construct();
self::$instance = $this;
class PlayerMgr extends APP_DbObject {
public static function getMaxScore() {
return hardback::$instance->getUniqueValueFromDB("SELECT MAX(player_score) FROM player WHERE player_eliminated = 0 AND player_zombie = 0");
}