Skip to content

Instantly share code, notes, and snippets.

@aaroneaton
Created March 17, 2015 03:14
Show Gist options
  • Save aaroneaton/d6cbd0642d1e9dcb736f to your computer and use it in GitHub Desktop.
Save aaroneaton/d6cbd0642d1e9dcb736f to your computer and use it in GitHub Desktop.
Conditional unserialize
<?php
// Instead of blindly returning $collection...
if ( $collection instanceof \Serializable ) {
// We know this would be a new collection
return $collection;
} else {
// This is a transient from the database so
// we need to use the native PHP unserialize function.
return unserialize( $collection );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment