You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implements nullable property declarations and proper null checks for typed properties to ensure compatibility with PHP 8.4+.
Improves error handling for uninitialized properties and enhances method logic to maintain backward compatibility with existing workflows.
Updates documentation to reflect these changes and provide guidance on new best practices for property management.
This document outlines the changes made to ensure full compatibility with PHP 8.4+ and proper handling of typed properties.
4
+
5
+
## Overview
6
+
7
+
With PHP 8.0+, typed properties must be explicitly initialized before they can be accessed. This application has been updated to handle this requirement properly while maintaining backward compatibility.
8
+
9
+
## Changes Made
10
+
11
+
### 1. Nullable Property Declarations
12
+
13
+
**Before:**
14
+
```php
15
+
public \DateTime $since;
16
+
public \DateTime $until;
17
+
```
18
+
19
+
**After:**
20
+
```php
21
+
public ?\DateTime $since = null;
22
+
public ?\DateTime $until = null;
23
+
```
24
+
25
+
### 2. Safe Property Access
26
+
27
+
All access to `$since` and `$until` properties now includes proper null checks:
28
+
29
+
```php
30
+
// Safe access pattern used throughout the codebase
31
+
if (isset($this->since, $this->until)) {
32
+
// Safe to use both properties
33
+
$period = $this->since->format('Y-m-d') . ' to ' . $this->until->format('Y-m-d');
34
+
}
35
+
36
+
// Safe single property access
37
+
if (isset($this->since)) {
38
+
$startDate = clone $this->since;
39
+
}
40
+
```
41
+
42
+
### 3. Method-Specific Improvements
43
+
44
+
#### `createInvoice()` Method
45
+
- Added null checks before accessing period properties
46
+
- Graceful fallback for invoice descriptions when period is undefined
47
+
- Safe due date setting only when `$until` is available
48
+
49
+
#### `createOrder()` Method
50
+
- Uses invoice start date as fallback when `$this->since` is not set
51
+
- Maintains functionality for both period-aware and period-agnostic workflows
52
+
53
+
#### `getIpexInvoices()` Method
54
+
- Properly initializes `$since` and `$until` at method start
55
+
- Safe to access these properties throughout the method execution
56
+
57
+
## Usage Patterns
58
+
59
+
### 1. With Period Definition (VoIPPostpaidOrders.php)
60
+
```php
61
+
$ipexer = new Ipex();
62
+
$report = $ipexer->processIpexPostpaidOrders(
63
+
$ipexer->getIpexInvoices(['monthOffset' => -2])
64
+
);
65
+
```
66
+
In this case, `getIpexInvoices()` initializes the period properties.
67
+
68
+
### 2. Without Period Definition (VoIPPostpaidInvoices.php)
69
+
```php
70
+
$ipexer = new Ipex();
71
+
$report = $ipexer->processIpexPostpaidInvoices();
72
+
```
73
+
In this case, methods handle null period properties gracefully.
74
+
75
+
## Benefits
76
+
77
+
1.**PHP 8.4+ Compatibility**: Full support for strict typed property requirements
78
+
2.**Backward Compatibility**: Existing workflows continue to function unchanged
79
+
3.**Error Prevention**: Eliminates "Typed property must not be accessed before initialization" errors
80
+
4.**Flexibility**: Supports both period-aware and period-agnostic processing modes
81
+
82
+
## Best Practices
83
+
84
+
When working with this codebase:
85
+
86
+
1. Always check `isset()` before accessing `$since` or `$until` properties
87
+
2. Provide fallback logic when period properties are not available
88
+
3. Use nullable types (`?Type`) for optional properties
89
+
4. Initialize properties with sensible defaults when possible
90
+
91
+
## Testing
92
+
93
+
The changes have been tested with:
94
+
- PHP 8.2.29 (production environment)
95
+
- PHP 8.4.x (development environment)
96
+
- Various workflow scenarios (with and without period definition)
97
+
98
+
All existing functionality remains intact while providing robust error handling for uninitialized properties.
0 commit comments