generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
What happened?
The PdfMeta::make() method in src/Models/PdfMeta.php throws a TypeError when PDF documents contain date fields (CreationDate, ModDate) as arrays instead of strings.
Root Cause
Lines 37-43 in PdfMeta.php assume date fields are always strings:
if ($creationDate) {
$creationDate = new DateTime($creationDate);
}
if ($modDate) {
$modDate = new DateTime($modDate);
}However, the underlying smalot/pdfparser library can return arrays when PDF metadata contains array structures (which is valid per PDF specification).
Error Message
TypeError: DateTime::__construct(): Argument #1 ($datetime) must be of type string, array given
Proposed Fix
Add type checking before DateTime construction:
if ($creationDate) {
if (is_array($creationDate)) {
// Handle array case - use first valid date
$validDate = array_filter($creationDate, function($date) {
return !empty($date) && is_string($date);
});
$creationDate = !empty($validDate) ? new DateTime(reset($validDate)) : null;
} else {
$creationDate = new DateTime($creationDate);
}
}
if ($modDate) {
if (is_array($modDate)) {
// Handle array case - use last valid date for modification date
$validDate = array_filter($modDate, function($date) {
return !empty($date) && is_string($date);
});
$modDate = !empty($validDate) ? new DateTime(end($validDate)) : null;
} else {
$modDate = new DateTime($modDate);
}
}Impact
- Affects PDF metadata extraction for certain PDF files
- Causes complete extraction failure rather than graceful degradation
How to reproduce the bug
This occurs with PDF files that have array-structured metadata fields
Package Version
latest
PHP Version
8.x
Which operating systems does with happen with?
No response
Notes
No response
ewilan-riviere
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working