[wp-trac] [WordPress Trac] #45895: maybe_unserialize: handle exceptions thrown during unserialization

WordPress Trac noreply at wordpress.org
Mon Mar 11 21:34:18 UTC 2019


#45895: maybe_unserialize: handle exceptions thrown during unserialization
-------------------------------------------------+-------------------------
 Reporter:  bluefuton                            |       Owner:  desrosj
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  5.2
Component:  General                              |     Version:  5.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests reporter-   |     Focuses:
  feedback needs-refresh                         |
-------------------------------------------------+-------------------------
Changes (by desrosj):

 * keywords:  has-patch has-unit-tests reporter-feedback => has-patch has-
     unit-tests reporter-feedback needs-refresh


Comment:

 Looking into it some more, I can't find any documentation anywhere that
 notes `unserialize()` would ever throw an exception. But, an exception is
 thrown when attempting to ''serialize'' a `SimpleXMLElement`.


 {{{
 add_action( 'init', function() {
         $xml = new SimpleXMLElement( '<xml></xml>' );

         $output = null;

         try {
                 $output = maybe_serialize( $xml );
         } catch ( Exception $e ) {
                 var_dump( $e );
         }

         var_dump( $output );
 });
 }}}

 It also seems that attempting to serialize a closure function will cause
 an exception.


 {{{
 add_action( 'init', function() {
         $closure_function = function(){
                 $test = 'some string';
         };

         $output = null;

         try {
                 $output = maybe_serialize( $closure_function );
         } catch ( Exception $e ) {
                 var_dump( $e );
         }

         var_dump( $output );
 });
 }}}

 Can you confirm that this is what you experienced, @bluefuton?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45895#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list