Skip to content

Fix namespace prefixing for built-in PHP types#19

Merged
akirk merged 2 commits intoakirk:mainfrom
obenland:fix/namespace-prefix-builtin-types
Sep 30, 2025
Merged

Fix namespace prefixing for built-in PHP types#19
akirk merged 2 commits intoakirk:mainfrom
obenland:fix/namespace-prefix-builtin-types

Conversation

@obenland
Copy link
Copy Markdown
Contributor

Summary

  • Fixes namespace prefixing incorrectly applying to built-in PHP types like null
  • Adds helper method maybe_prefix_namespace() to centralize namespace logic
  • Includes test case to prevent regression

Problem

When a namespace was configured, built-in PHP types were being incorrectly prefixed. For example:

/**
 * @param null   $pre      The pre-existing value.
 * @param string $username The username.
 */
$pre = apply_filters( 'activitypub_pre_get_by_username', null, $username );

Would generate documentation showing ActivityPub\null instead of just null.

Solution

  • Created maybe_prefix_namespace() helper method to handle all namespace prefixing logic in one place
  • Expanded list of built-in types to exclude: null, mixed, void, false, true, callable, resource, iterable
  • Applied fix to both parameter and return type handling

Test Plan

  • Added test case test_null_param_without_namespace_prefix() with fixture
  • Test fails before fix (shows ActivityPub\null)
  • Test passes after fix (shows null)
  • All 38 existing tests still pass

Previously, when a namespace was configured, built-in PHP types like
`null` were incorrectly prefixed with the namespace (e.g.,
`ActivityPub\null`). This fix:

- Adds `maybe_prefix_namespace()` helper to centralize namespace logic
- Excludes all built-in types: null, mixed, void, false, true, callable,
  resource, iterable
- Adds test case to verify null and other built-in types are not prefixed
@akirk
Copy link
Copy Markdown
Owner

akirk commented Sep 30, 2025

Thank you!

@akirk akirk merged commit a53989c into akirk:main Sep 30, 2025
1 check passed
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.

2 participants