[BUGFIX] Fix TypeError in HeadlessUserInt::unwrap() when preg_replace_callback returns null#866
Open
Rhovan2223 wants to merge 1 commit intoTYPO3-Headless:masterfrom
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
HeadlessUserInt::unwrap()declaresstringas its return type, butpreg_replace_callback()can returnnullon internal failure (as documented in the PHP manual).This causes a sporadic
TypeErrorin 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 fourpreg_replace_callback()calls inunwrap(), so the original content is preserved instead of returningnull.This is the minimal, non-breaking fix — no behavioral change when
preg_replace_callback()succeeds.Changes
Classes/Utility/HeadlessUserInt.php: Add?? $contentto all 4preg_replace_callback()calls