Skip to content

PHP 8.3 TypeError in date element: get_date_format_string() argument #2 must be of type string, null given #737

@Trarco

Description

@Trarco

A TypeError is thrown when rendering a Custom Certificate using the Date element. This occurs because the $dateformat property is null, but the helper method expects a mandatory string. This is particularly prevalent in PHP 8.x environments.

Environment

  • Moodle Version: 4.5.8
  • PHP Version: 8.3.6

Error Details / Stack Trace

Exception - mod_customcert\element_helper::get_date_format_string(): Argument #2 ($dateformat) must be of type string, null given, called in [dirroot]/mod/customcert/element/date/classes/element.php on line 269

Stack trace:
line 749 of /mod/customcert/classes/element_helper.php: TypeError thrown
line 269 of /mod/customcert/element/date/classes/element.php: call to mod_customcert\element_helper::get_date_format_string()
line 143 of /mod/customcert/rearrange.php: call to customcertelement_date\element->render_html()

Steps to Reproduce

  1. Use Moodle 4.5+ with PHP 8.3.
  2. Create or edit a Custom Certificate.
  3. Access the Rearrange elements page (rearrange.php).
  4. Add or view a "Date" element
  5. Set the date format (example used: "6 July 2026")
  6. Save or attempt to view the certificate
  7. The page fails to load with the TypeError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions