Fix PHP 8 date() timestamp casts (fixes #132)#133
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates several files to cast event timestamps to integers before passing them to the date() function, ensuring compatibility with PHP 8.1+. It also fixes a bug in logstreamdisk.class.php where the wrong field variable was used during date grouping. The review feedback highlights a potential issue in logstreamdisk.class.php where log array fields might be strings rather than arrays. To prevent PHP 8 warnings and incorrect date grouping, it is recommended to defensively check if these fields are arrays and fall back to strtotime() if they are strings.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| 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] ); | ||
| } |
There was a problem hiding this comment.
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 to 2 and resulting in "1970-01-01").\n\nWe should defensively check if the field is an array, and fallback to parsing it with strtotime if it is a string, similar to how it is handled in GetFormatedDate.
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() );
}| 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] ); | ||
| } |
There was a problem hiding this comment.
Similar to the issue in ConsolidateItemListByField, if $logArray[$szConsFieldId] is a string rather than an array, accessing it as an array will cause PHP 8 warnings or incorrect date grouping. We should defensively check if it is an array and fallback to strtotime if it is a string.
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() );
}| 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] ); | ||
| } |
There was a problem hiding this comment.
Similar to the other consolidation methods, if $logArray[$szFieldId] is a string rather than an array, accessing it as an array will cause PHP 8 warnings or incorrect date grouping. We should defensively check if it is an array and fallback to strtotime if it is a string.
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() );
}|
@codex review |
@alorbach I have started the AI code review. It will take a few minutes to complete. |
|
To use Codex here, create a Codex account and connect to github. |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Cast event timestamps to int before date() for PHP 8.1+
PHP 8.1+ requires an integer for date()'s timestamp parameter. Passing
numeric strings (or other non-int values) from event-time arrays triggers
deprecation notices; PHP 8.4+ can throw TypeError. This broke disk-source
statistics/charts reported in #132 and could affect other code paths that
format EVTIME_TIMESTAMP values without casting.
Disk logstream (logstreamdisk.class.php)
variable $szFieldId -> $szConsFieldId when grouping by date fields
Grid display (functions_frontendhelpers.php)
$evttimearray[EVTIME_TIMESTAMP], +86400 expressions, and $nMyTimeStamp
Search filters (logstreamdb/pdo/clickhouse.class.php)
$myeventtime[EVTIME_TIMESTAMP] before building SQL date literals
Export (export.php)
ChangeLog: document fix under 5.0.2 Robustness; credit @KDocProf.
Fixes #132