[wp-trac] [WordPress Trac] #18488: set_transient crashes when value parameter is a SimpleXMLElement object

WordPress Trac wp-trac at lists.automattic.com
Sun Aug 21 02:42:01 UTC 2011


#18488: set_transient crashes when value parameter is a SimpleXMLElement object
--------------------------+------------------------------
 Reporter:  bobbingwide   |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cache         |     Version:  3.2.1
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by dd32):

 > Can't the routine detect that I'm passing an object and cast it to a
 string?

 Well, no, You can't just cast an object to a string, SimpleXML provides a
 nice toString() functionality though which allows you to do that to
 SimpleXML objects.

 WordPress calls PHP's Serialize function to convert the object to a string
 notation for storage, and then the unserialize() function to convert that
 string back into the object upon retrieval.

 When you're using SimpleXML, you need to be aware that it's not a "simple"
 class instance you're using, SimpleXML classes are much more complex than
 that, they're pretty much a representation of a file handle, and as such,
 are only usable within the context they're created, They can't be saved,
 if you need to cache them, then you need to convert it to a string (be
 that via the toXML() method, or by casting the value to a string)

 Since we're using PHP5 now, We could wrap all serialize() calls in a try
 {} catch(e) {} block and return false to prevent fatal errors, but that'll
 most likely only cause more confusion as people don't understand why the
 functions not storing their objects, As it is, the error message should be
 descriptive to PHP Developers as to what the problem is and should only
 ever occur at development time, never to be seen in production
 environments.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18488#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list