Skip to content

Latest commit

 

History

History
134 lines (97 loc) · 3.58 KB

File metadata and controls

134 lines (97 loc) · 3.58 KB

PHP 8 Migration Guide for mudCMS

This document outlines the changes made to upgrade mudCMS from PHP 7.x to PHP 8.2+.

Summary of Changes

1. PHP Version Requirement

  • Before: No explicit PHP version requirement
  • After: php: ^8.2
  • Benefit: Access to latest language features, improved performance, better type safety

2. PHPUnit Upgrade

  • Before: PHPUnit 9
  • After: PHPUnit 11
  • Benefit: Better compatibility with PHP 8.2+, improved testing features

3. PHP 8 Features Already in Use

The codebase already uses several PHP 8+ features:

  • Typed properties (e.g., private PDO $conn in PostRepo)
  • Named parameters (PDO parameter binding)
  • Return type declarations (e.g., get_total_posts(): int)

PHP 8.2 Specific Improvements

Type System Enhancements

PHP 8.2 brings improved type handling with readonly properties and better union types. While these aren't applied yet, they're available for future refactoring.

Performance

  • 5-10% faster execution than PHP 8.0
  • Better memory management
  • Improved JIT compilation

Migration Checklist

  • Update PHP requirement in composer.json
  • Update PHPUnit to v11
  • Verify type declarations are compatible
  • Test with PHP 8.2 runtime
  • Review deprecated function usage
  • Update deployment configurations

Deprecated Functions to Check

The following functions were deprecated in PHP 7.4+ and removed/changing in PHP 8+:

Status in Current Codebase

  • ini_set() - Still supported but consider alternatives
  • include()/require() - Still supported, consider autoloading
  • Session functions - Still supported, but consider modern session handling

Recommended Future Improvements

  1. Replace dynamic includes with autoloading

    // Before
    include("assets/init.php");
    
    // After (with proper composer.json autoloading)
    use Secret\MudCms\Initialization;
  2. Type hints for all functions

    // Before
    public function get_posts_latest($amnt, $offset = 0)
    
    // After (PHP 8+)
    public function get_posts_latest(int $amnt, int $offset = 0): array
  3. Named arguments (PHP 8.0+)

    // New capability
    $posts = $postRepo->get_posts_latest(amnt: 10, offset: 0);

Compatibility Notes

  • ✅ PDO is fully compatible with PHP 8.2
  • ✅ GD extension works perfectly in PHP 8.2
  • ✅ All current code is forward-compatible

Testing PHP 8.2 Compatibility

To test locally:

# Verify PHP version
php -v

# Run composer update
composer update

# Run PHPUnit tests
php vendor/bin/phpunit

Environment Configuration

Update your deployment environment:

Docker Example:

FROM php:8.2-apache

RUN docker-php-ext-install pdo pdo_mysql gd

System Requirements:

  • PHP 8.2 or later
  • MySQL 5.7+ or MariaDB 10.3+
  • Apache 2.4+ with mod_rewrite enabled

Breaking Changes from PHP 7

Most code remains compatible. Key differences:

  1. Strict parameter type checking - More enforced
  2. Removed functions - Already not used in mudCMS
  3. Error handling - More strict about null safety

Next Steps

  1. ✅ Update composer.json (COMPLETED)
  2. Run full test suite on PHP 8.2 environment
  3. Update CI/CD pipelines to PHP 8.2
  4. Deploy to staging for validation
  5. Monitor production for any issues

Support

For questions about PHP 8 features, refer to: