| 25 | | The unit tests added in [62408] assert the **return type of the function** |
| 26 | | (string), object uniqueness, stability, and null for malformed input. They do |
| 27 | | not assert the **type of the resulting array key** in `WP_Hook::$callbacks`, |
| 28 | | which is where the coercion happens. A regression test should read back |
| 29 | | `array_keys( $wp_filter[ $hook ]->callbacks[ $priority ] )` and assert the key |
| 30 | | is a string. |
| | 20 | The unit tests added in [62408] assert the **return type of the function** (string), object uniqueness, stability, and null for malformed input. They do not assert the **type of the resulting array key** in `WP_Hook::$callbacks`, which is where the coercion happens. A regression test should read back `array_keys( $wp_filter[ $hook ]->callbacks[ $priority ] )` and assert the key is a string. |
| 54 | | `WP_Hook::$callbacks` is a public property introspected by caching, profiling, |
| 55 | | and debugging plugins. Any consumer under `strict_types`, or passing the key to |
| 56 | | a `string`-typed parameter, now fatals. Confirmed in the wild: WP Rocket |
| 57 | | (`Cloudflare.php`, `substr()` on the key) broke immediately on 7.1. |
| | 43 | `WP_Hook::$callbacks` is a public property introspected by caching, profiling, and debugging plugins. Any consumer under `strict_types`, or passing the key to a `string`-typed parameter, now fatals. Confirmed in the wild: WP Rocket (`Cloudflare.php`, `substr()` on the key) broke immediately on 7.1. |
| 60 | | 1. Normalize the object branch to a non-numeric string (e.g. a short constant |
| 61 | | prefix) so the key can never be coerced. This makes the existing `(string)` |
| 62 | | cast actually effective. Trade-off: reintroduces a concat/allocation that |
| 63 | | [62408] removed from the hot path. |
| 64 | | 2. Cast keys to string at the `WP_Hook` read/iteration boundaries. |
| 65 | | 3. Accept int keys as intended, document it on `@return` and on |
| 66 | | `WP_Hook::$callbacks`, and treat consumers as responsible. |
| 67 | | |
| 68 | | In all cases, add a regression test asserting the **stored key type**, not just |
| 69 | | the function return type. |
| 70 | | |
| 71 | | Introduced in [62408]. Related: #64898. |
| | 46 | 1. Normalize the object |