Opened 9 months ago

Last modified 9 months ago

#21650 new defect (bug)

replace serialize() with print_r() in stats() function in wp-includes/cache.php

Reported by: bobbingwide Owned by:
Priority: normal Milestone: Awaiting Review
Component: Cache Version: 3.4.1
Severity: minor Keywords: has-patch
Cc:

Description

In PHP 5.3 it is no longer possible to serialize data that contains a SimpleXMLElement object. It produces a fatal error. See https://bugs.php.net/bug.php?id=49800

The stats() function attempts to determine the allocated space for objects in the cache by using strlen() of the serialized object.

This can fail for the reason above.

Given that the figure returned is simply an estimation of the space
I propose that the code is changed to use
print_r( $cache, true ) instead of serialize( $cache )

ie. to become
echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( print_r( $cache, true ) ) / 1024, 2 ) . 'k )</li>';

This TRAC was raised after a longish chain of events starting with #18488 and the final response (today) which led to another chance discovery of a similar problem in the debug-bar plugin.

http://wordpress.org/support/topic/plugin-debug-bar-fatal-error-uncaught-exception-serialization-of-simplexmlelement-is-not-allowed

Attachments (1)

cache.php.21650.diff (564 bytes) - added by bobbingwide 9 months ago.
Replace serialize() with print_r() to avoid Fatal error (WP 3.5)

Download all attachments as: .zip

Change History (4)

Replace serialize() with print_r() to avoid Fatal error (WP 3.5)

  • Severity changed from normal to minor

The way this estimation is presented is very misleading; it makes you think you're viewing the size of the cache in memory, rather than the lenght of it's serialization.

Other than that, switching to print_r() seems sane.

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.