Skip to content

Bug: TypeError in ModuleTimeTable.php on PHP 8.4+ #49

@preiss-wa

Description

@preiss-wa

Description

When running Contao 5.3 with cgoit/calendar-extended-bundle 2.6.0 on PHP 8.4, the timetable module throws a fatal TypeError that breaks the page rendering.

Error message

request.CRITICAL: Uncaught PHP Exception TypeError: "date(): Argument #2 ($timestamp) must be of type ?int, string given" at ModuleTimeTable.php line 168

Cause

Starting with PHP 8.4, date() strictly enforces that its second argument must be ?int. In ModuleTimeTable.php, several values passed to date() are strings:

  1. Line 168: $this->Date->tstamp — Contao's Date object may return the timestamp as a string
  2. Lines ~183ff: $objMinMax->dateFrom, $objMinMax->dateTo, $objMinMax->repeatUntil — database query results are always returned as strings in PHP
  3. compileDays() method: $this->weekBegin, $vv['startTime'], $vv['endTime'] — also potentially strings
  4. setWeekStartAndEnd() method: $newDate->tstamp — same issue

On PHP 8.3 these were silently accepted. On PHP 8.4+ they cause a fatal TypeError.

Steps to reproduce

  1. Install Contao 5.3 with cgoit/calendar-extended-bundle 2.6.0
  2. Switch to PHP 8.4
  3. Create a page with a timetable module that has calendar events
  4. Open the page in the frontend

Expected behavior

The timetable renders without errors.

Actual behavior

Page throws a fatal TypeError and fails to render.

Suggested fix

Cast all values passed as the second argument to date() to (int). The affected locations are:

  • compile(): (int) $this->Date->tstamp
  • compile(): (int) $objMinMax->dateFrom, (int) $objMinMax->dateTo, (int) $objMinMax->repeatUntil
  • compileDays(): (int) $this->weekBegin, (int) $vv['startTime'], (int) $vv['endTime']
  • setWeekStartAndEnd(): (int) $newDate->tstamp

Environment

  • Contao: 5.3.45
  • PHP: 8.4
  • Bundle version: 2.6.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions