OOB: Require strict types in every PHP file - #21
Open
nikolaystrikhar wants to merge 1 commit into
Open
Conversation
`declare( strict_types=1 );` in all 51 files under src/ and tests/, one blank line below the file-level docblock and one above the namespace. The declaration governs the call site, so what it buys is our own calls outward: an int or a null reaching a WordPress function that declared string now fails on the line that passed it rather than coercing to "0" or "" and surfacing as a wrong value downstream. The hook boundary is unchanged -- WordPress's own files are not strict, so core calling our typed methods still coerces weakly. CLAUDE.md carries the rule so new files inherit it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
declare( strict_types=1 );in all 51 PHP files undersrc/andtests/, plus the CLAUDE.md convention that keeps new files strict.Usage:
Why this way:
It is the call site that matters, not the signatures. The declaration governs calls made from the file, so the value is in our calls outward: an
intornullreaching a WordPress function that declaredstringfails on the line that passed it, instead of coercing to"0"and surfacing as a wrong value downstream.The hook boundary is untouched. WordPress's own files are not strict, so core calling our typed methods still coerces weakly — no callback changes behaviour, and nothing reached from a hook gains a new way to throw.
Tests are strict too. A weak test file calling into strict production code would pass arguments production never accepts, and the suite would be proving the wrong thing.