Skip to content

Critical PHP 8+ Compatibility Issue: Dynamic Property Deprecation Breaks SDK Initialization #6

@aregowe

Description

@aregowe

🐛 Critical PHP 8+ Compatibility Issue: Dynamic Property Deprecation Breaks SDK Initialization

🚨 Issue Summary

The FlagShip API SDK v1.1.23 is incompatible with PHP 8.0+ due to deprecated dynamic property creation patterns. This causes fatal errors in PHP 8.2+ and deprecation warnings in PHP 8.0-8.1, completely breaking SDK functionality in modern PHP environments.

🔍 Environment Details

  • SDK Version: flagshipcompany/flagship-api-sdk v1.1.23 (September 2022)
  • PHP Requirement: >=7.1 (in composer.json)
  • Problem Versions: PHP 8.0+ (deprecated), PHP 8.2+ (fatal errors)
  • Affected Environments: Production, staging, and development servers running modern PHP

💥 The Error

PHP 8.0-8.1 (Deprecation Warning):

Deprecated: Creation of dynamic property Flagship\Shipping\Flagship::$apiUrl is deprecated 
in /vendor/flagshipcompany/flagship-api-sdk/Shipping/Flagship.php on line 43

PHP 8.2+ (Fatal Error):

Fatal error: Creation of dynamic property Flagship\Shipping\Flagship::$apiUrl is not allowed

🎯 Root Cause Analysis

Primary Issue Location

File: Flagship.php (lines 42-46)

class Flagship{

    public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){
        // ❌ Dynamic property creation (deprecated in PHP 8.0+)
        $this->apiUrl = $apiUrl;           // Line 43 - Main error source
        $this->apiToken = $apiToken;       // Line 44
        $this->flagshipFor = $flagshipFor; // Line 45  
        $this->version = $version;         // Line 46
    }

Problem: The class has no property declarations, causing PHP to create them dynamically at runtime.

Additional Affected Files

The same pattern exists across multiple core classes:

  1. ApiRequest.php - Abstract base class

    • Dynamic properties: $url, $token, $payload, $headers, etc.
  2. Shipping/Objects/*.php - All shipping object classes:

    • Rate.php, Shipment.php, Address.php, Manifest.php
    • Package.php, Pickup.php, Service.php, TrackShipment.php

🔧 Technical Solution

Required Fix

Add explicit protected property declarations to all affected classes:

Before (Broken on PHP 8+):

class Flagship{
    // No property declarations

    public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){
        $this->apiUrl = $apiUrl; // ❌ Creates dynamic property

After (PHP 8+ Compatible):

class Flagship{
    // ✅ Explicit property declarations
    protected $apiUrl;
    protected $apiToken;
    protected $flagshipFor;
    protected $version;

    public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){
        $this->apiUrl = $apiUrl; // ✅ Assigns to declared property

📊 Impact Assessment

Affected Systems

  • E-commerce Platforms: Magento, WooCommerce, Shopify integrations
  • Shipping Calculations: All rate requests fail
  • API Integration: Complete SDK initialization failure
  • Production Environments: Any server running PHP 8+

User Impact

  • No shipping rates available - Customers cannot complete checkout
  • Fatal application errors - Complete system crashes on PHP 8.2+
  • Integration failures - All FlagShip API functionality broken
  • E-commerce disruption - Revenue loss due to checkout failures

🧪 Reproduction Steps

  1. Install SDK in PHP 8+ environment:

    composer require flagshipcompany/flagship-api-sdk
  2. Attempt SDK initialization:

    use Flagship\Shipping\Flagship;
    
    $flagship = new Flagship('token', 'https://api.flagshipcompany.com', 'magento');
    // ❌ Throws deprecation warning (PHP 8.0-8.1) or fatal error (PHP 8.2+)
  3. Observe error in logs or application crash

💡 Proposed Solution

Immediate Fix (Backward Compatible)

Add property declarations to all affected classes without changing functionality:

// In Shipping/Flagship.php
class Flagship{
    protected $apiUrl;
    protected $apiToken; 
    protected $flagshipFor;
    protected $version;
    
    // Existing constructor remains unchanged
    public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){
        $this->apiUrl = $apiUrl;
        $this->apiToken = $apiToken;
        $this->flagshipFor = $flagshipFor;
        $this->version = $version;
    }

Full File List Requiring Updates

Based on SDK analysis, these files need property declarations:

Core Classes:

  • Flagship.php ⭐ Critical
  • ApiRequest.php ⭐ Critical

Object Classes:

  • Shipping/Objects/Rate.php
  • Shipping/Objects/Shipment.php
  • Shipping/Objects/Address.php
  • Shipping/Objects/Manifest.php
  • Shipping/Objects/Package.php
  • Shipping/Objects/Pickup.php
  • Shipping/Objects/Service.php
  • Shipping/Objects/TrackShipment.php

📋 Additional Context

  • SDK Age: Last major update September 2022 (before PHP 8.2 release)
  • Current PHP Support: Claims >=7.1 but breaks on 8.0+
  • Community Impact: Affects all e-commerce integrations using modern PHP
  • Business Critical: Shipping functionality is essential for e-commerce operations

🎯 Priority: CRITICAL

This issue completely breaks the SDK on modern PHP versions and affects all users running PHP 8+. The fix is straightforward but requires a new release to resolve properly.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions