-
Notifications
You must be signed in to change notification settings - Fork 0
Description
🐛 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-sdkv1.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:
-
ApiRequest.php - Abstract base class
- Dynamic properties:
$url,$token,$payload,$headers, etc.
- Dynamic properties:
-
Shipping/Objects/*.php- All shipping object classes:Rate.php,Shipment.php,Address.php,Manifest.phpPackage.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 propertyAfter (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
-
Install SDK in PHP 8+ environment:
composer require flagshipcompany/flagship-api-sdk
-
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+)
-
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.phpShipping/Objects/Shipment.phpShipping/Objects/Address.phpShipping/Objects/Manifest.phpShipping/Objects/Package.phpShipping/Objects/Pickup.phpShipping/Objects/Service.phpShipping/Objects/TrackShipment.php
📋 Additional Context
- SDK Age: Last major update September 2022 (before PHP 8.2 release)
- Current PHP Support: Claims
>=7.1but 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.