Skip to content

Conversation

@DmitriyStoyanov
Copy link

@DmitriyStoyanov DmitriyStoyanov commented Oct 14, 2025

This PR addresses critical compatibility issues that arose after upgrading from Ubuntu 20.04 to 22.04 and PHP 7.4 to 8.1. The upgrade was necessary to maintain system security and receive ongoing OS support, but initially broke several application components as documented in issue #3133

The PHP 8.1 upgrade introduced breaking changes that affected:

  • AWS SDK compatibility (v2 → v3 migration required)
  • Deprecated PHP syntax (curly brace array access)

Without these fixes, the application was unable to run on Ubuntu 22.04, preventing essential OS security updates.

So I've implemented next changes:
AWS SDK Migration:

  • Upgraded AWS SDK from v2 to v3 in EC2 functions (www/ec2/ec2.inc.php)
  • Updated Composer dependencies to use latest AWS SDK v3.337.3
  • Removed legacy AWS SDK v2 from www/lib/aws and AWS SDK v3 from www/lib/aws_v3/ directories
  • Migrated EC2 client instantiation to use new v3 syntax and namespacing

PHP 8.1 Compatibility Fixes:

  • Fixed curly brace syntax in www/lib/S3.php
  • Resolved callback function errors for responseHeaderCallback and responseWriterCallback
  • Added defensive file existence checks before accessing some files and temporary directories
  • Fix PHP 8+ type errors in video comparison pages
  • Fix imagerectangle null error in waterfall.inc
  • Fix htmlspecialchars array error in timings.blade.php

Tested successfully on our Private WPT Server with WPT Agents

Fixed three PHP 8+ type errors that were causing warnings in WPT Server:

1. Unsupported operand types: string / int
   - Fixed in filmstrip.inc.php: Added is_numeric() check before dividing test['end'] by interval
   - Fixed in compare.php (2 locations): Added type checks when calculating filmstrip_end_time and testEnd
   - All division operations now validate types and use explicit float casting

2. imagerectangle(): Argument catchpoint#1 must be of type GdImage, null given
   - Fixed in waterfall.inc: Added check to ensure imagecreatetruecolor() succeeds before using image resource
   - Returns null if image creation fails to prevent null pointer errors

3. round(): Argument catchpoint#1 must be of type int|float, string given
   - Fixed in visualProgress.inc.php: Added is_numeric() check before calling round() on visual_progress values
   - Ensures values are numeric before rounding operations

All fixes include:
- Type validation using is_numeric() where needed
- Explicit type casting with (float) for arithmetic operations
- Null/false checks for image resource creation
- Safe fallback values when operations cannot proceed

These changes maintain backward compatibility while preventing PHP 8+ type errors.
Added comprehensive null checks for image resource to prevent PHP 8+ type errors:

1. Enhanced image creation validation:
   - Added check for both resource (PHP 7) and GdImage object (PHP 8+)
   - Added @ suppression operator to prevent warnings on failure
   - Returns null early if image creation fails

2. Added defensive checks in helper functions:
   - DrawPerfLabel(): Validates $im before using it
   - DrawPerfBackground(): Validates $im before using it
   - Both functions now return early if image is invalid

3. Added guards before all imagerectangle() calls:
   - Line 530: Main border drawing
   - Line 570: Interactive section border
   - Line 912: Long tasks border
   - Line 1025: Left column border

This ensures that imagerectangle() is never called with a null or invalid
image resource, preventing the PHP 8+ type error:
'imagerectangle(): Argument catchpoint#1 ($image) must be of type GdImage, null given'
Fixed PHP 8+ type error when custom metric values are arrays:
'htmlspecialchars(): Argument catchpoint#1 ($string) must be of type string, array given'

The issue occurred when custom metrics contain array values that were
passed directly to Blade's {{ }} syntax, which automatically calls
htmlspecialchars() on the value.

Solution:
- Added type checking before output in the template
- Arrays and objects are now converted to JSON strings using json_encode()
- String and numeric values are output normally
- This prevents the type error while preserving data for display

This ensures compatibility with PHP 8+ strict type checking while
maintaining backward compatibility with existing data structures.
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.

1 participant