Created
March 17, 2015 03:14
-
-
Save aaroneaton/d6cbd0642d1e9dcb736f to your computer and use it in GitHub Desktop.
Conditional unserialize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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