Skip to content

OOB: Require strict types in every PHP file - #21

Open
nikolaystrikhar wants to merge 1 commit into
mainfrom
strict-types
Open

OOB: Require strict types in every PHP file#21
nikolaystrikhar wants to merge 1 commit into
mainfrom
strict-types

Conversation

@nikolaystrikhar

Copy link
Copy Markdown
Contributor

What: declare( strict_types=1 ); in all 51 PHP files under src/ and tests/, plus the CLAUDE.md convention that keeps new files strict.

Usage:

<?php
/**
 * @package Nexcess\PluginAbsorber
 */

declare( strict_types=1 );

namespace Nexcess\PluginAbsorber;

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 int or null reaching a WordPress function that declared string fails 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.

`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.
@nikolaystrikhar nikolaystrikhar changed the title Require strict types in every PHP file OOB: Require strict types in every PHP file Aug 13, 2026
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