maybe_unserialize( string $data ): mixed

Unserializes data only if it was serialized.


Parameters

$data string Required
Data that might be unserialized.

Top ↑

Return

mixed Unserialized data can be any type.


Top ↑

More Information

Data might need to be serialized to allow it to be successfully stored and retrieved from a database in a form that PHP can understand.


Top ↑

Source

File: wp-includes/functions.php. View all references

function maybe_unserialize( $data ) {
	if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
		return @unserialize( trim( $data ) );
	}

	return $data;
}


Top ↑

Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.