Skip to content

feat: support PHP 8.1 via #[ScopeShared] attribute - #5

Merged
roxblnfk merged 1 commit into
1.xfrom
feat/php-8.1-support
Sep 8, 2026
Merged

feat: support PHP 8.1 via #[ScopeShared] attribute#5
roxblnfk merged 1 commit into
1.xfrom
feat/php-8.1-support

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Sep 8, 2026

Copy link
Copy Markdown
Member

🔍 What was changed

Lowers the minimum PHP version to 8.1 and adds a #[ScopeShared] attribute (TARGET_CLASS, no parameters) that marks a service to be shared across scopes instead of cloned per-scope.

State::clone() now shares a cached service with the child scope when it is an enum, a readonly class (guarded by PHP_VERSION_ID >= 80200), or carries #[ScopeShared]. composer.json and psalm.xml are moved to 8.1.

Why?

Scope cloning already shares immutable services with the parent instead of cloning them, detecting them via ReflectionClass::isReadOnly(). Both readonly class and that reflection method are 8.2-only, so on 8.1 there was no way to mark a service as safe-to-share. #[ScopeShared] provides that in a version-independent way — and also covers classes that are immutable in practice but not declared readonly.

Checklist

  • Closes PHP 8.1 #4
  • How was this tested:
    • Unit tests added

Review notes

CI still runs on 8.2+ only: Testo does not support 8.1 yet (blocked by php-testo/testo#322). Adding 8.1 to the matrix is tracked separately in #6.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

Lower the minimum PHP version to 8.1. Since `readonly class` and ReflectionClass::isReadOnly() are 8.2-only, add a #[ScopeShared] attribute that opts a service out of per-scope cloning explicitly, so the same instance is shared across the whole scope tree on any supported version.

State::clone() now shares a service when it is an enum, a readonly class (8.2+), or carries #[ScopeShared].

Refs #4

Assisted-By: Claude Opus 4.8 (1M context)
@roxblnfk
roxblnfk force-pushed the feat/php-8.1-support branch from a3c7efd to b483030 Compare September 8, 2026 09:17
@roxblnfk
roxblnfk merged commit 76dfe0b into 1.x Sep 8, 2026
12 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 8, 2026
@roxblnfk
roxblnfk deleted the feat/php-8.1-support branch September 8, 2026 09:43
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.

PHP 8.1

1 participant