Skip to content

Introduce new type-safe methods for receiving config section values#24404

Merged
sgiehl merged 6 commits into5.x-devfrom
configgetters
Apr 27, 2026
Merged

Introduce new type-safe methods for receiving config section values#24404
sgiehl merged 6 commits into5.x-devfrom
configgetters

Conversation

@sgiehl
Copy link
Copy Markdown
Member

@sgiehl sgiehl commented Apr 21, 2026

Description

This changes the section config helpers to support typed access with optional typed defaults, and updates existing manual-cast call sites to use those helpers while preserving previous behavior.

What changed

SectionConfig now provides typed getters for config values:

  • getIntegerConfigValue(string $name, ?int $default = null, ?int $idSite = null): ?int
  • getFloatConfigValue(string $name, ?float $default = null, ?int $idSite = null): ?float
  • getBoolConfigValue(string $name, ?bool $default = null, ?int $idSite = null): ?bool
  • getStringConfigValue(string $name, ?string $default = null, ?int $idSite = null): ?string
  • getArrayConfigValue(string $name, ?array $default = null, ?int $idSite = null): ?array

Behavior:

  • If the config value is missing, the typed default is returned.
  • If the value cannot be cast to the requested type, a warning is logged and the typed default is returned.
  • If no default is provided, null is returned.

TrackerConfig was refactored to extend SectionConfig, while keeping the use_third_party_id_cookie special handling.

Existing call sites that previously did manual casts on GeneralConfig, DatabaseConfig, or TrackerConfig were updated to use the typed getters instead. Where the old code relied on PHP cast fallback behavior, explicit defaults were added so behavior stays the same:

  • old (int) casts now pass 0
  • old (bool) / !! casts now pass false
  • old (string) casts now pass ''

Why

This avoids repeating ad-hoc casts throughout the codebase, makes the expected type explicit at the config access point, and centralizes invalid-value handling and logging.

Notes

The migrated call sites were reviewed to preserve previous semantics. In particular, places that previously depended on PHP cast behavior now pass explicit defaults instead of implicitly returning null.

Checklist

  • [✔] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Review

@sgiehl sgiehl added the Technical debt Issues the will help to reduce technical debt label Apr 21, 2026
@sgiehl sgiehl added this to the 5.10.0 milestone Apr 21, 2026
@sgiehl sgiehl marked this pull request as ready for review April 21, 2026 14:43
@sgiehl sgiehl requested a review from a team April 21, 2026 14:44
caddoo
caddoo previously approved these changes Apr 21, 2026
Copy link
Copy Markdown
Contributor

@caddoo caddoo left a comment

Choose a reason for hiding this comment

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

A nice change, just a comment.

How can we encourage using the specially typed functions though going forward?

And move away from people using getConfigValue

Comment thread core/Config/SectionConfig.php
@sgiehl
Copy link
Copy Markdown
Member Author

sgiehl commented Apr 22, 2026

@caddoo I considered marking the method as @deprecated, but that would actually be wrong. There might be rare cases where using that method would still be needed. Like if e.g. the type could be an array or a string value.
I've now added a comment to the method, that using the type safe variants should be preferred. Hopefully that will cause at least the AI to follow the suggestion 🙈

@sgiehl sgiehl requested a review from caddoo April 22, 2026 08:54
@sgiehl sgiehl merged commit 64d8da2 into 5.x-dev Apr 27, 2026
30 checks passed
@sgiehl sgiehl deleted the configgetters branch April 27, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Technical debt Issues the will help to reduce technical debt

Development

Successfully merging this pull request may close these issues.

3 participants