WordPress.org

Make WordPress Core

Opened 15 months ago

Last modified 3 months ago

#20357 new enhancement

Add Return Empty String Function

Reported by: wpsmith Owned by:
Priority: normal Milestone: Awaiting Review
Component: General Version:
Severity: normal Keywords: has-patch
Cc: justin@…

Description

There's an easy way to return boolean, integer (0), and an empty array. But what about an empty string?
root\wp-includes\functions.php

/**
 * Returns an empty string.
 *
 * Useful for returning an empty string to filters easily.
 *
 * @since 3.0.0
 * @see __return_empty_string()
 * @return string Empty string
 */
function __return_empty_string() {
	return '';
}

Attachments (1)

20357.diff (663 bytes) - added by trepmal 7 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 nacin15 months ago

There is also one for null, which could be used in nearly all places __return_empty_string() might be used. Where might one use it, though? I closed #20358.

comment:2 follow-up: wpsmith15 months ago

I probably missed it but where is the return null function? I see __return_false but don't see __return_null. If I am not mistaken those are two different ideas/purposes. Likewise, if one wishes to be consistent with types, it would be beneficial to have __return_empty_string and maybe even __return_null (if it doesn't exist already).

Last edited 15 months ago by wpsmith (previous) (diff)

comment:3 nacin15 months ago

__return_null is new in 3.4, I think.

comment:4 in reply to: ↑ 2 SergeyBiryukov15 months ago

Replying to wpsmith:

I probably missed it but where is the return null function?

It was added in #18845.

trepmal7 months ago

comment:5 trepmal7 months ago

  • Keywords has-patch added

Added a patch since this ticket wasn't closed, just in case...

Using __return_null when I really want an empty string seems hackish.

There are at least 3 plugins in the repo doing their own version of __return_empty_string but 1 returns the parameter passed to it, and another actually echoes an empty string. Not sure if only 3 attempts is an indication that there's not a big enough need, or if that 2 of 3 attempts doing it wrong indicates there should be a core function to save them.

comment:6 jtsternberg3 months ago

  • Cc justin@… added

Agreed. Seems hackish. Any word from the powers that be?

Note: See TracTickets for help on using tickets.