Skip to content

Conversation

@lacatoire
Copy link

Summary

This PR marks all private promoted properties that are never reassigned as readonly.

Motivation

  • Improves immutability guarantees for internal classes.
  • Helps static analyzers (PHPStan, Psalm) infer data flow more accurately.
  • Aligns PhD with modern PHP conventions and safety features introduced in PHP 8.1.

Scope

  • Scanned all constructor-promoted properties.
  • Identified private ones never written to outside the constructor.
  • Declared them readonly.

Example

Before:
class Reader {
public function __construct(private string $path) {}
}

After:
class Reader {
public function __construct(private readonly string $path) {}
}

Impact

  • ✅ No behavior change.
  • ✅ Pure internal safety improvement.
  • ✅ Forward-compatible with PHP 8.4+.
  • 🧠 Enables better static analysis and type inference.

References

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.

1 participant