Skip to content

Conversation

markinigor
Copy link
Contributor

Summary

Changed return type from self to static in fromArray() method and abstract fromParams() method to fix polymorphism issues.

Motivation and Context

Using self as return type breaks polymorphic behavior since self always refers to the abstract parent class, while static refers to the actual subclass being called at runtime.

This ensures subclasses return the correct type when calling these methods.

How Has This Been Tested?

Not tested - this is a type annotation fix only, runtime behavior unchanged.

Breaking Changes

Minor breaking change in type annotations only. Runtime behavior remains the same.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the [MCP Documentation](https://modelcontextprotocol.io)
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Simple type annotation fix:

// Before
abstract protected static function fromParams(?array $params): self;

// After  
abstract protected static function fromParams(?array $params): static;

@chr-hertel
Copy link
Member

Hey, thanks, not sure there's something to fix here - if you convince phpstan, you convince me :)

Anyhow, if you're looking for contributing, we have a couple of open issues in the issue tracker and feature contributions are very much welcome!

@markinigor
Copy link
Contributor Author

@chr-hertel Ready to run qa.

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

so, you convinced us i guess :D

@chr-hertel
Copy link
Member

@markinigor not all of your commits are not verified at this point, please squash to one verified commit.

@markinigor
Copy link
Contributor Author

@chr-hertel I've signed all commits with GPG.

@chr-hertel chr-hertel merged commit 20e789d into modelcontextprotocol:main Sep 9, 2025
9 checks passed
@chr-hertel chr-hertel changed the title Fix return type in abstract methods from self to static [Server] Fix return type in abstract methods from self to static Sep 21, 2025
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants