Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHP coding standards to avoid calling static methods with self #486

Open
GuySartorelli opened this issue Mar 26, 2024 · 2 comments
Open

Comments

@GuySartorelli
Copy link
Member

We had a bug which it turned out was caused by an unexpected interaction between self and late static binding (see this PR).
This was raised in php-src where the response was that it was working as intended.

Going forward we should avoid calling static methods from self to avoid this class of bug.

Acceptance Criteria

  • The PHP coding standards are updated to explicitly disallow calling static methods with self (e.g. self::get())
  • The docs mention the rationale, i.e. we're avoiding a specific class of bug that is introduced when using late static binding downstream from self
  • static is fine, because it explicitly uses late static binding anyway

TO DECIDE

  • Are there any scenarios where self is allowed? e.g. is self okay in a type hint, and is self::class okay? Or is is better to just avoid self altogether (e.g. use the explicit class name, or __CLASS__ as a replacement of self::class)?
@maxime-rainville
Copy link
Contributor

Is there an actual issue that got cause by this? e.g. Did we have a scenario where we called self::get() in Link wanting to query all Links and ended up querying only FileLink.

@GuySartorelli
Copy link
Member Author

Is there an actual issue that got cause by this?

Yes. I'll link you the slack thread.

@GuySartorelli GuySartorelli added this to the Silverstripe CMS 5.3 milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants