WordPress at a glance

__return_empty_array() WP 3.0.0

Simply returns an empty array: array(). Helper function of WordPress.

Useful for returning an empty array to filters easily.

All such helper functions:
__return_false() — returns false.
__return_true() — returns true.
__return_empty_array() — returns an empty: array().
__return_zero() — returns the number 0.
__return_null() — returns NULL.
__return_empty_string() — returns an empty string: ''.


Array. Empty array.

1 time = 0.000001s = speed of light | 50000 times = 0.01s = speed of light | PHP 7.1.11, WP 4.9.7

No Hooks.


__return_empty_array() // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore;


#1 Demonstrate the use of

Suppose that in the filter 'my_filter' we need to always return an empty array():

add_filter( 'my_filter', '__return_empty_array' );

The same can be written so:

// example of anonymous function
add_filter( 'my_filter', create_function('','return array();') );

// or so for php 5.3+
add_filter( 'my_filter', function(){ return array(); } );

// or so, with the registration function
add_filter( 'my_filter', 'my_return_function' );
function my_return_function(){
	return array();

Список изменений

С версии 3.0.0 Введена.

Code of __return_empty_array() WP 5.5.1

function __return_empty_array() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
	return array();

Related Functions

From tag: __return (helper functions)

More from category: Helper Functions

No comments
    Log In . Register