Skip to content

refactor: add PHP 8.3 types to BC-safe class constants - #63133

Merged
solracsf merged 1 commit into
masterfrom
chore/php83-typed-class-constants
Aug 11, 2026
Merged

refactor: add PHP 8.3 types to BC-safe class constants#63133
solracsf merged 1 commit into
masterfrom
chore/php83-typed-class-constants

Conversation

@solracsf

Copy link
Copy Markdown
Member
  • Resolves: #

Summary

PHP 8.3 allows class constants to declare a type. Adopt it where doing so cannot break third-party apps.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@solracsf solracsf added this to the Nextcloud 35 milestone Aug 10, 2026
@solracsf solracsf added the ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) label Aug 10, 2026
@solracsf
solracsf requested review from Altahrim, leftybournes, provokateurin and salmart-dev and removed request for a team August 10, 2026 15:28
@CarlSchwan CarlSchwan added the 4. to release Ready to be released and/or waiting for tests to finish label Aug 10, 2026
Comment thread apps/dav/lib/CalDAV/Import/TextImporter.php Outdated
Comment thread apps/dav/lib/CalDAV/Import/XmlImporter.php Outdated
@solracsf
solracsf force-pushed the chore/php83-typed-class-constants branch from aaf4508 to ea0608f Compare August 10, 2026 16:35
@solracsf

Copy link
Copy Markdown
Member Author

@SebastianKrupinski Under the looser standard ("public const in a class nothing extends"), generalized repo-wide, many other constants would qualify. I deliberately did not apply those. "No subclass in this repo" is not "No subclass", the list literally includes CalDavBackend, a known third-party extension surface.

If you want that expansion, let me know.

@miaulalala
miaulalala removed their request for review August 11, 2026 09:32
@solracsf
solracsf force-pushed the chore/php83-typed-class-constants branch from ea0608f to 12a5aae Compare August 11, 2026 12:51
PHP 8.3 allows class constants to declare a type. Adopt it where doing so
cannot break third-party apps.

Typing an inheritable constant is a hard BC break: a subclass that
redeclares it untyped fails to load with "Type of C::FOO must be
compatible with P::FOO of type string". Changes are therefore limited to
constants that cannot be redeclared by a subclass:

  - private const (not inherited)
  - final public/protected const
  - constants declared in a final class or an enum

Interface constants, trait constants, and public/protected constants in
non-final (including abstract) classes are left untyped, as is all of
lib/public (OCP) and lib/unstable (NCU).

One review-requested exception: the public OBJECT_PREFIX/OBJECT_SUFFIX
constants of the app-internal CalDAV import helpers (TextImporter,
XmlImporter) are typed as well; these classes are not public API and
have no subclasses.

Only string, int and array are used. float is avoided because it would
silently coerce an int literal and change === comparisons. No constant
name or value is modified: every changed line adds only the type token,
so runtime behaviour is unchanged.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf
solracsf force-pushed the chore/php83-typed-class-constants branch from 12a5aae to 4920bd1 Compare August 11, 2026 12:53
@solracsf
solracsf enabled auto-merge August 11, 2026 12:53
@solracsf
solracsf merged commit a28cd1f into master Aug 11, 2026
218 of 221 checks passed
@solracsf
solracsf deleted the chore/php83-typed-class-constants branch August 11, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release Ready to be released and/or waiting for tests to finish ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants