[wp-trac] [WordPress Trac] #64703: Code Modernization: Replace void in PHPDoc union return types with null in class-wpdb.php
WordPress Trac
noreply at wordpress.org
Mon Feb 23 09:33:39 UTC 2026
#64703: Code Modernization: Replace void in PHPDoc union return types with null in
class-wpdb.php
--------------------------+-----------------------------
Reporter: apermo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 4.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Following up on [#64694] which fixed `paginate_links()`, this ticket
addresses 3 instances in `class-wpdb.php` where `@return` annotations
incorrectly use `void` as part of a union type.
The `|void` pattern was introduced in WordPress 4.3 via [32654] for
`prepare()` and `check_connection()`, and in WordPress 5.5 via [47944] for
`get_row()`.
=== Why this matters ===
In PHP's type system, `void` means "the function does not return a value"
and '''cannot''' be part of a union type (this is a compile error in PHP
8.0+). When a function uses bare `return;` or falls off the end without
returning, the actual runtime value is `null`. Therefore `@return
Type|void` should be `@return Type|null`.
This affects:
* Static analysis tools (PHPStan, Psalm)
* IDE autocompletion and type inference
* Developer expectations about return values
=== Backward Compatibility ===
This is a safe, non-breaking change. As demonstrated by @westonruter in
the [https://github.com/WordPress/wordpress-
develop/pull/10999#pullrequestreview-3839142928 #64694 PR review],
`return;` and `return null;` are identical at runtime across every PHP
version from 4.3.0 through 8.5.3: https://3v4l.org/3KQC8
=== Proposed Changes ===
For each instance:
1. Update the `@return` annotation to replace `void` with `null` (or
remove `|void` where the function always returns a typed value)
2. Change bare `return;` statements to `return null;`
3. Update description text to say "null" instead of "void" / "nothing"
=== Affected Functions ===
||= Function =||= Line =||= Current =||= Recommendation =||= Since =||
|| `prepare()` || 1456 || `string|void` || `string|null` || 4.3 ||
|| `check_connection()` || 2120 || `bool|void` || `bool` (void incorrect —
always returns bool or terminates) || 4.3 ||
|| `get_row()` || 3059 || `array|object|null|void` || `array|object|null`
(void redundant — already includes null) || 5.5 ||
**Note on `prepare()`:** Uses bare `return;` on error paths. The change to
`return null;` is safe, but the error-path behavior should be reviewed to
confirm `null` is the intended signal for "no query".
See [#64694] for prior art.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64703>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list