-
Notifications
You must be signed in to change notification settings - Fork 43
Fix PHP 8 date() timestamp casts (fixes #132) #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -821,7 +821,7 @@ public function ConsolidateItemListByField($szConsFieldId, $nRecordLimit, $szSor | |
| if ( $nConsFieldType == FILTER_TYPE_DATE ) | ||
| { | ||
| // Convert to FULL Day Date for now! | ||
| $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); | ||
| $myFieldData = date( "Y-m-d", (int)$logArray[$szConsFieldId][EVTIME_TIMESTAMP] ); | ||
| } | ||
| else // Just copy the value! | ||
| $myFieldData = $logArray[$szConsFieldId]; | ||
|
|
@@ -914,7 +914,7 @@ public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFie | |
| if ( $nConsFieldType == FILTER_TYPE_DATE ) | ||
| { | ||
| // Convert to FULL Day Date for now! | ||
| $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); | ||
| $myFieldData = date( "Y-m-d", (int)$logArray[$szConsFieldId][EVTIME_TIMESTAMP] ); | ||
| } | ||
|
Comment on lines
914
to
918
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the issue in if ( $nConsFieldType == FILTER_TYPE_DATE )
{
// Convert to FULL Day Date for now!
$nTimeStamp = is_array($logArray[$szConsFieldId]) ? (int)$logArray[$szConsFieldId][EVTIME_TIMESTAMP] : strtotime($logArray[$szConsFieldId]);
$myFieldData = date( "Y-m-d", $nTimeStamp !== false ? $nTimeStamp : time() );
} |
||
| else // Just copy the value! | ||
| $myFieldData = $logArray[$szConsFieldId]; | ||
|
|
@@ -1017,7 +1017,7 @@ public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit) | |
| if ( $nFieldType == FILTER_TYPE_DATE ) | ||
| { | ||
| // Convert to FULL Day Date for now! | ||
| $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); | ||
| $myFieldData = date( "Y-m-d", (int)$logArray[$szFieldId][EVTIME_TIMESTAMP] ); | ||
| } | ||
|
Comment on lines
1017
to
1021
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other consolidation methods, if if ( $nFieldType == FILTER_TYPE_DATE )
{
// Convert to FULL Day Date for now!
$nTimeStamp = is_array($logArray[$szFieldId]) ? (int)$logArray[$szFieldId][EVTIME_TIMESTAMP] : strtotime($logArray[$szFieldId]);
$myFieldData = date( "Y-m-d", $nTimeStamp !== false ? $nTimeStamp : time() );
} |
||
| else // Just copy the value! | ||
| $myFieldData = $logArray[$szFieldId]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
$logArray[$szConsFieldId]is a string (e.g., a pre-formatted date string from a custom log parser) rather than an array, attempting to access$logArray[$szConsFieldId][EVTIME_TIMESTAMP]will result in an illegal string offset warning in PHP 8, or incorrectly extract a single character and cast it to an incorrect timestamp (e.g.,"2"from"2023-..."casting to2and resulting in"1970-01-01").\n\nWe should defensively check if the field is an array, and fallback to parsing it withstrtotimeif it is a string, similar to how it is handled inGetFormatedDate.