Skip to content

Navigation: Use self:: to access private static members - #86090

Merged
westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-navigation-self-access
Nov 1, 2026
Merged

westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-navigation-self-access

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

What?

See #86088

Replaces static:: with self:: when WP_Navigation_Block_Renderer accesses its own private static methods and properties, and removes the resolved entries from the PHPStan baseline.

Why?

PHPStan reports calls to private methods and access to private properties through static:: as unsafe (staticClassAccess.privateMethod and staticClassAccess.privateProperty). Late static binding with static:: implies that a subclass may provide the member, but a subclass can never see a private member, so self:: is the accurate reference. Together, these changes clear 49 of the 226 errors initially baselined in #66693.

How?

  • Replaced all 48 occurrences of static:: with self:: in packages/block-library/src/navigation/index.php. Every occurrence refers to a private member of the class itself, and the only public method, render(), is not called through static::.
  • Removed the 27 corresponding staticClassAccess.* entries for this file from tools/phpstan/baseline.neon.

There is no change in behavior: the class has no subclasses, and private members resolve to the declaring class either way.

Testing Instructions

  1. Run composer phpstan and confirm it passes with no unmatched ignored errors.
  2. Run composer phpstan:baselines and confirm tools/phpstan/baseline.neon has no further changes.
  3. Run the Navigation renderer tests: npm run test:php -- --filter WP_Navigation_Block_Renderer_Test.
  4. Optional smoke test: add a Navigation block with a submenu to a page, then check that it renders on the front end and that the responsive overlay menu opens and closes as before.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

I used Claude Code to identify the affected occurrences and draft the change. I reviewed the diff and take responsibility for it.

`WP_Navigation_Block_Renderer` accessed its private static methods and properties through `static::`, which PHPStan reports as unsafe since a subclass cannot see private members. Use `self::` instead and remove the 27 resolved entries from the PHPStan baseline.

See WordPress#86088.
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@huzaifaalmesbah huzaifaalmesbah added [Type] Code Quality Issues or PRs that relate to code quality [Block] Navigation Affects the Navigation Block labels Nov 1, 2026
@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review November 1, 2026 01:42
@westonruter
westonruter merged commit 9772756 into WordPress:trunk Nov 1, 2026
114 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Nov 1, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
)

`WP_Navigation_Block_Renderer` accessed its private static methods and properties through `static::`, which PHPStan reports as unsafe since a subclass cannot see private members. Use `self::` instead and remove the 27 resolved entries from the PHPStan baseline.

See WordPress#86088.

Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants