2 years ago ∙ 2 minutes read
Recently, I developed a couple of helper functions for transmitting PHP objects over the wire, and saving them in database records:
dehydrate()- recursively converts an instance of a PHP class to a plain untyped object. Then, store the plain object in the database, or convert it to JSON and send it to a browser.
hydrate()- recursively converts a plain untyped object back to a PHP class instance. Use if after decoding a JSON received from the browser, or after loading a database record.
This article describes how to use these functions.