XF 2.3 serialize vs json for custom fields

stromb0li

Well-known member
Licensed customer
In new add-ons, is the recommendation to serialize or json encode data to the database where needed? In general, it seems like development patterns are moving away from serialize/unserialize to json_encode/decode. Even PHP's unserialize documentation goes as far as making this recommendation now: https://www.php.net/manual/en/function.unserialize.php

I'm curious if it's "best practice" to follow XenForo consistency of serialize/unserialize for new add-ons, or if I should work with json instead?
 
I'm curious if it's "best practice" to follow XenForo consistency of serialize/unserialize for new add-ons
Most remaining serialized data in the core was migrated to JSON in XF 2.1.0 seven years ago (though there are vanishingly few places that still use serialized data where appropriate). When in doubt, I'd stick to JSON.
 
(though there are vanishingly few places that still use serialized data where appropriate)
Sorry for double post, but the place I am targeting is custom field values. It looks like custom field definitions use json, but the values stored for the user don't?

I just noticed XF uses Php::safeUnserialize(); I'll switch to that instead of unserialize as-is.
 
Last edited:
Back
Top Bottom