__return_null()WP 3.4.0

Simply returns null. Auxiliary function of WordPress.

Designed for use in filters, to not to register a function when you want to return null.

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: ''.

1 time — 0.000001 sec (speed of light) | 50000 times — 0.00 sec (speed of light) | PHP 7.1.11, WP 4.9.7

No Hooks.

Return

null. Nothing (null).

Usage

__return_null();

Examples

0

#1 Example of usage

Let's say that we should always return null in the filter 'my_filter'. Then, use this code:

add_filter( 'my_filter', '__return_empty_string' );

The same we can write so:

// anonymous function - php 5.3+
add_filter( 'my_filter', function(){ return null; } );

// or with registering function
add_filter( 'my_filter', 'my_return_function' );
function my_return_function(){
	return null;
}

Changelog

Since 3.4.0 Introduced.

__return_null() code WP 6.4.3

function __return_null() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
	return null;
}