Skip to content

[BUGFIX] Fix TypeError in HeadlessUserInt::unwrap() when preg_replace_callback returns null#866

Open
Rhovan2223 wants to merge 1 commit intoTYPO3-Headless:masterfrom
Rhovan2223:bugfix/fix-unwrap-null-return-type
Open

[BUGFIX] Fix TypeError in HeadlessUserInt::unwrap() when preg_replace_callback returns null#866
Rhovan2223 wants to merge 1 commit intoTYPO3-Headless:masterfrom
Rhovan2223:bugfix/fix-unwrap-null-return-type

Conversation

@Rhovan2223
Copy link

Problem

HeadlessUserInt::unwrap() declares string as its return type, but preg_replace_callback() can return null on internal failure (as documented in the PHP manual).

This causes a sporadic TypeError in production environments:
TypeError: FriendsOfTYPO3\Headless\Utility\HeadlessUserInt::unwrap(): Return value must be of type string, null returned
The issue is intermittent and hard to reproduce, but occurs under real-world load.

Fix

Add the null coalescing operator (?? $content) to all four preg_replace_callback() calls in unwrap(), so the original content is preserved instead of returning null.

This is the minimal, non-breaking fix — no behavioral change when preg_replace_callback() succeeds.

Changes

  • Classes/Utility/HeadlessUserInt.php: Add ?? $content to all 4 preg_replace_callback() calls

preg_replace_callback() can return null on failure, but unwrap() declares string as return type. This causes a sporadic TypeError.

Add null coalescing operator ( ?? ) to all preg_replace_callback() calls so the original content is returned instead of null.
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

Comments