Skip to content

feat: update php to 7+ and fix compatibility issues#6

Open
sale4319 wants to merge 9 commits intotarnus:masterfrom
sale4319:feat-upgrade-php-version
Open

feat: update php to 7+ and fix compatibility issues#6
sale4319 wants to merge 9 commits intotarnus:masterfrom
sale4319:feat-upgrade-php-version

Conversation

@sale4319
Copy link
Copy Markdown

@sale4319 sale4319 commented Feb 28, 2026

What did I do?

Branch: feat-upgrade-php-version

PHP 7+ Compatibility & Dependency Upgrade

Goal: Modernize the codebase to run cleanly on PHP 7+.

Changes:

  • PHPMailer upgraded to v6 via Composer, replacing the legacy bundled copy
  • 102 game class files updated for PHP 7+ compatibility (constructor renames, deprecated syntax, etc.)
  • Core app, config, and support files updated for PHP 7+ compat
  • Backend libraries normalized from CRLF→LF and updated to modern class syntax
  • @ error suppression replaced with proper conditional checks throughout
  • Repo hygiene: vendor/, composer.phar, templates_c/ added to .gitignore / untracked; duplicate PHPMailer removed

Commits:

  • d606bb5 chore: normalize CRLF→LF and modernize class syntax in backend libraries
  • 4400341 feat: upgrade PHPMailer to v6 via Composer
  • 4bfbeac fix: PHP 7+ compat in core app, config, and support files
  • d1f0e40 fix: PHP 7+ compat in game class files (102 files)
  • f1f796b chore: repo hygiene — untrack vendor, composer.phar, templates_c; remove duplicate PHPMailer
  • 079b1da fix: replace @ error suppression with proper conditionals

PHP 7+ / 8+ Compatibility

  • Guarded get_magic_quotes_gpc() call behind a PHP_VERSION_ID < 80000 check to avoid fatal errors on PHP 8
  • Removed deprecated pass-by-reference-on-new (=& new) syntax in SwiftMailer usage in login_process.php
  • Replaced legacy $HTTP_GET_VARS / $HTTP_POST_VARS superglobals with $_GET / $_POST throughout
  • Fixed unquoted array index interpolation in strings (e.g. $arr[key]$arr['key']) across core files

MySQL Compatibility

  • Replaced deprecated mysql_get_server_info() with mysqli_get_server_info($db->connectionId)
  • Added SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION' on connect to support MySQL 5.7+ strict mode (schema uses 0000-00-00 datetime defaults)

PHPMailer Integration

  • Added composer.json requiring phpmailer/phpmailer ^6.9
  • Added composer.lock and vendor with PHPMailer 6.x (namespaced PHPMailer\PHPMailer)
  • Added PHPMailer source to `PHPMailer as a local copy alongside Composer install

⚙️php.ini Overhaul

  • Commented out PHP 5.2-era eaccelerator and ZendOptimizer extensions (incompatible with modern PHP)
  • Added short_open_tag = On to support legacy <? open tags used throughout the codebase
  • Set error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE, display_errors = On, log_errors = On

Bug Fixes

  • Fixed IP ban query in login_process.php to guard against empty ban_mask / email columns (prevents unintended wildcard matches)
  • Added $create_game != 1 guard in config.php to suppress false "page loading" lag warnings during game creation
  • Added null-safe guard for $template_object initialisation in scheduler.php to prevent fatal errors when running via CLI

Refactoring / Code Quality

  • Extracted shared calc_scan_ratio() helper from SCAN_SUCCESS() and SCAN_ERROR() to eliminate duplicated logic
  • Fixed SCAN_ERROR() — on successful scan now returns the exact value instead of a near-value with 99–101% jitter
  • Rewrote get_dirlist() to use scandir() instead of the manual opendir()/readdir()/closedir() pattern
  • Cleaned up close_database() — removed dead $db->close() call with explanatory comment
  • Removed numerous commented-out debug statements and dead code across core files
  • Added missing $gameroot to template_display() global declaration

Frontend

  • Updated all template footer.tpl files to persist the countdown timer in sessionStorage, preventing it from resetting on every page navigation

Line Ending Normalisation

  • Converted CRLF → LF across the majority of backend library files (adodb_lite, adodbSQL_drivers, libchart, pseudo-cron, template_lite, class files, etc.)

Files Changed (across all branches)

File Change
global_sched_funcs.php Scan fix + parameter removal
class/ (102 files) PHP 7+ compatibility
global_funcs.php, config, support files PHP 7+ compatibility
Backend library files CRLF normalisation + modern syntax
composer.json PHPMailer v6 dependency
.gitignore Untrack vendor, composer.phar, templates_c

@tarnus
Copy link
Copy Markdown
Owner

tarnus commented Feb 28, 2026

Hey, thanks for taking this on — the PHP 7+ compatibility fixes are solid work and definitely needed. I've got some notes before we can merge though:

Repo hygiene:

  • composer.phar (3.3MB binary) and the entire vendor/ directory are committed. These should be .gitignore'd — composer install handles vendor at deploy time.
  • templates_c/cpuinfo.tmp is a temp/cache file that snuck in. Should also be ignored.
  • PHPMailer exists in two places now — backends/PHPMailer/ (manual copy) and vendor/phpmailer/phpmailer/ (via composer). Pick one; the composer-managed version is the way to go.
  • We need a .gitignore update to cover vendor/, composer.phar, and templates_c/.

Line endings:
~75% of this diff is line ending changes, which makes it really hard to review the actual code. Can you normalize line endings in a separate commit (or set up a .gitattributes) and keep this PR focused on the PHP changes?

Behavioral changes that should be separate:

  • SCAN_ERROR() used to return a fuzzy value (99–101% of correct) on a successful scan. Now it returns the exact value. That's a gameplay balance change, not a compat fix — should be its own PR with an explanation.
  • phpMaxCreditsDelta() had its $currentvalue parameter removed. Need to verify no callers pass two args, or this will throw warnings.

Minor stuff:

  • The @ error suppression on ini_set, get_magic_quotes_gpc, and mysqli_get_server_info — would be cleaner to use proper conditionals (you're already doing PHP_VERSION_ID checks in one spot, just apply that pattern consistently).
  • One commit for 435 files is tough to bisect if something breaks. If you can break it into logical chunks (line endings, PHP compat, PHPMailer upgrade, scan refactor) that'd be ideal.

The core compat work is good — just needs some cleanup to get it mergeable. Happy to re-review once updated.

- Add .gitattributes to enforce LF line endings going forward
- Convert CRLF to LF across all backend/vendor library files
  (adodb_lite, adodbSQL_drivers, SwiftMailer, template_lite,
   libchart, pseudo-cron, phpfreechat, PHPMailer)
- Replace deprecated `var` property declarations with `public`
  in adodb driver classes (PHP 7/8 compatibility)
- No functional logic was changed in this commit
@sale4319 sale4319 force-pushed the feat-upgrade-php-version branch from 02e7a6e to 60230e4 Compare February 28, 2026 08:52
Replace the manually-copied PHPMailer 5 tree with a Composer-managed
v6 install.  composer.json/composer.lock track the dependency;
vendor/phpmailer/phpmailer/ contains the new source (PHPMailer.php,
SMTP.php, POP3.php, Exception.php, DSNConfigurator.php, OAuth.php
plus updated language files).
Update all class/*.inc files for PHP 7/8 compatibility:
- Remove deprecated ereg/eregi → preg_match/preg_replace
- Replace split() → explode() / preg_split()
- Fix mysql_* → mysqli_* where still present
- Remove magic_quotes assumptions
- Add missing return types / strict comparisons where applicable
Apply ereg->preg, split->explode, mysql->mysqli and magic-quotes-removal
to all non-class source files:

- admin/, admin.php
- casino/casino_roulette.inc
- config/config.php, config/config_sched.php, config/windowscron.txt
- contact_admin_thanks.php, create_game/, create_game.php
- email_player.php, feedback.php, footer.php, global_funcs.php
- globals/ (AAT_mbstring.inc, move_player_finish.inc, probe_detect.inc)
- installer.php, installer/ (30.inc, 40.inc, 999.inc)
- login_process.php, new_player_process.php, planet_report_ce.php
- php.ini: raise memory_limit / max_execution_time defaults
- scheduler.php, scheduler/ (sched_optimize, sched_repair, sched_tournament)
- support/ (variables.inc, variables0.inc, log_data lang files, casino.ini)
- team_chat.php
- templates/ (footer.tpl, about_template_options.inc for all 6 themes)
…ove duplicate PHPMailer

- Update .gitignore: replace 'templates_c/*.php' with 'templates_c/' (full dir),
  add vendor/ and composer.phar so they are never committed again
- git rm --cached vendor/ composer.phar templates_c/index.html: untrack 88 files
  that should never have been committed; local copies preserved for dev use
- git rm backends/PHPMailer/: delete manual copy of PHPMailer (Exception.php,
  PHPMailer.php, SMTP.php) — the composer-managed vendor/phpmailer/phpmailer/ is
  the canonical version; no code references the backends copy directly
- ini_set('session.use_trans_sid'): drop @ — ini_set never emits a
  warning for valid session.* keys in PHP 7+
- get_magic_quotes_gpc(): already guarded by function_exists(), @ was
  redundant; removed
- mysqli_get_server_info(): replace @ with an explicit instanceof mysqli
  check so a missing/null connection ID surfaces early rather than
  silently returning empty
- extension_loaded(): never throws; removed @ in config.php,
  config_sched.php and installer/30.inc
@sale4319 sale4319 force-pushed the feat-upgrade-php-version branch from 2270d59 to 079b1da Compare February 28, 2026 09:38
@sale4319
Copy link
Copy Markdown
Author

Hey, thanks for taking this on — the PHP 7+ compatibility fixes are solid work and definitely needed. I've got some notes before we can merge though:

Repo hygiene:

  • composer.phar (3.3MB binary) and the entire vendor/ directory are committed. These should be .gitignore'd — composer install handles vendor at deploy time.
  • templates_c/cpuinfo.tmp is a temp/cache file that snuck in. Should also be ignored.
  • PHPMailer exists in two places now — backends/PHPMailer/ (manual copy) and vendor/phpmailer/phpmailer/ (via composer). Pick one; the composer-managed version is the way to go.
  • We need a .gitignore update to cover vendor/, composer.phar, and templates_c/.

Line endings: ~75% of this diff is line ending changes, which makes it really hard to review the actual code. Can you normalize line endings in a separate commit (or set up a .gitattributes) and keep this PR focused on the PHP changes?

Behavioral changes that should be separate:

  • SCAN_ERROR() used to return a fuzzy value (99–101% of correct) on a successful scan. Now it returns the exact value. That's a gameplay balance change, not a compat fix — should be its own PR with an explanation.
  • phpMaxCreditsDelta() had its $currentvalue parameter removed. Need to verify no callers pass two args, or this will throw warnings.

Minor stuff:

  • The @ error suppression on ini_set, get_magic_quotes_gpc, and mysqli_get_server_info — would be cleaner to use proper conditionals (you're already doing PHP_VERSION_ID checks in one spot, just apply that pattern consistently).
  • One commit for 435 files is tough to bisect if something breaks. If you can break it into logical chunks (line endings, PHP compat, PHPMailer upgrade, scan refactor) that'd be ideal.

The core compat work is good — just needs some cleanup to get it mergeable. Happy to re-review once updated.

Hi Tarnus,

Thank you for such a detailed comment, I addressed all the issues that you pointed out, I reworked commit history so my changes should be easier to review. I also provided detailed change log in PR description so that we have it as documentation.

There is still work in progress, I will QA the game locally to see if there are some bugs, and I will fix what I find.

I will ping you (🔔 --> @tarnus) for review and we can decide what and if we merge. 😄

Root causes fixed:
- PHP/MySQL timezone mismatch (DST drift) caused UNIX_TIMESTAMP() vs time()
  to disagree, triggering false idle logouts
- sessionStorage timer sync caused the footer countdown to jump backwards
  on every page load instead of always starting from the server-authoritative value
- Heartbeat pings incremented refreshcount, making active players look idle
- Scheduler idle-logout query had no margin for heartbeat timing races

Changes:
  config/config.php
  - date_default_timezone_set('UTC') -- pins PHP to UTC
  - SET time_zone='+00:00' on every DB connection -- pins MySQL to UTC
  - Lag-delay guard now also checks REQUEST_URI and excludes ajax_processor.php
  - Refresh-count tracking skips AJAX/heartbeat requests
  - Track $_SESSION['currenturi'] alongside currentprogram

  config/config_sched.php
  - Same UTC anchors (date_default_timezone_set + SET time_zone) for scheduler

  ajax/heartbeat.inc (new)
  - Lightweight endpoint; checklogin() via ajax_processor.php already updates
    last_login so no extra SQL is needed

  footer.php
  - Pass $idle_max to all templates

  scheduler/sched_turns.inc
  - Idle-logout threshold raised to ($idle_max + 2) min to absorb heartbeat
    timing races without affecting per-request session enforcement

  templates/*/footer.tpl (all 6 themes)
  - Remove sessionStorage timer sync; trust server-provided seconds_until_update
  - Add _sendHeartbeat(): fires at myi==10 (early warning), myi<=0 (tick),
    every 2 min if user is active, and on visibility-change (tab resume)
  - Idle gate on the 2-min interval: only sends heartbeat if user interacted
    within the idle window, letting genuinely idle sessions expire naturally
  - Move <table> before <script> so getElementById('myx') resolves immediately

  support/variables0.inc
  - Default player_online_timelimit set to 0 (unlimited) for new game installs
galaxy_map.php / templates (all 6 themes)
- Fix off-by-one: use < $endsector instead of <= so the last sector of
  the previous page is not duplicated on the next page
- Fix map row rendering: emit bare <TR>/<TR> tags (sector icons are
  rendered separately); pad incomplete last row with empty <TD>s so the
  grid stays aligned

new_player_process.php
- Guard ban check against empty columns: wrap ban_mask match in
  (ban_mask != '' AND ...) and email match in (email != '' AND ...) so
  rows with one field blank do not cause false positive bans

templates/*/planet_unowned/planet_scan.tpl (all 6 themes)
- Fix broken resource icons: images live at images/{name}.png, not the
  non-existent images/ports/{name}.png subdirectory
- Fix Smarty variable in default_menu_classic: {planettype} -> {$planettype}

support/variables0.inc
- Default account_creation_closed to 0 (open) for new installs
- Default enable_pseudo_cron to 0 (use real cron instead)
SCAN_ERROR() success branch previously returned the exact value; restore
original behaviour where a successful scan returns a slightly fuzzy result:
  floor(correct_value * rand(99999999, 100999999) / 100000000)
giving approximately 99-101% of the true value.
@sale4319 sale4319 force-pushed the feat-upgrade-php-version branch from 0101bd2 to f30e2fc Compare March 1, 2026 11:07
@sale4319 sale4319 marked this pull request as ready for review March 1, 2026 13:13
@tarnus
Copy link
Copy Markdown
Owner

tarnus commented Mar 5, 2026

Great work on the restructure — you addressed pretty much everything from the first review. The commit history is clean, repo hygiene is solid, and the timezone/heartbeat approach for the session desync is well thought out.

One thing to fix before merge:

scheduler/sched_turns.inc — the code after the idle-logout query got collapsed onto a few lines. The while loop, if/else, and TextFlush calls are all jammed together on single lines. Looks like a rebase or editor mishap. PHP doesn't care, but it's unreadable and inconsistent with the rest of the codebase. Quick reformat and we're good.

Other than that, this is ready to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants