Skip to content

Fix PHP 8 date() timestamp casts (fixes #132)#133

Merged
alorbach merged 1 commit into
masterfrom
pr-issue-132
Jun 8, 2026
Merged

Fix PHP 8 date() timestamp casts (fixes #132)#133
alorbach merged 1 commit into
masterfrom
pr-issue-132

Conversation

@alorbach

@alorbach alorbach commented Jun 8, 2026

Copy link
Copy Markdown
Member

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)

  • ConsolidateItemListByField: cast (int) on EVTIME_TIMESTAMP; fix wrong
    variable $szFieldId -> $szConsFieldId when grouping by date fields
  • ConsolidateDataByField: same variable fix and (int) cast
  • GetCountSortedByField: (int) cast (chartgenerator.php / Error in logstreamdisk.class.php #132 trigger path)

Grid display (functions_frontendhelpers.php)

  • GetFormatedDate: cast all date() timestamp args derived from
    $evttimearray[EVTIME_TIMESTAMP], +86400 expressions, and $nMyTimeStamp

Search filters (logstreamdb/pdo/clickhouse.class.php)

  • DATEMODE_RANGE_FROM / RANGE_TO / RANGE_DATE: cast (int) on
    $myeventtime[EVTIME_TIMESTAMP] before building SQL date literals

Export (export.php)

  • Cast (int) on period_start_ts / period_end_ts in export filename

ChangeLog: document fix under 5.0.2 Robustness; credit @KDocProf.

Fixes #132

Fixes disk chart/report consolidation (#132), grid date formatting, search filter SQL builders, and export filenames; correct wrong field variable in two disk consolidation helpers.

closes #132

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Re-trigger cubic

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 821 to 825
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] );
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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() );
					}

Comment on lines 914 to 918
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] );
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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() );
					}

Comment on lines 1017 to 1021
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] );
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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() );
					}

@alorbach

alorbach commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@codex review
@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown

@codex review
@cubic-dev-ai review

@alorbach I have started the AI code review. It will take a few minutes to complete.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Re-trigger cubic

@alorbach alorbach merged commit 53f5889 into master Jun 8, 2026
6 checks passed
@alorbach alorbach deleted the pr-issue-132 branch June 8, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in logstreamdisk.class.php

1 participant