Skip to content

Instantly share code, notes, and snippets.

@3lpsy
Created September 16, 2020 15:14
Show Gist options
  • Save 3lpsy/5f04e3bc35aa86e343c6123a901c7a3e to your computer and use it in GitHub Desktop.
Save 3lpsy/5f04e3bc35aa86e343c6123a901c7a3e to your computer and use it in GitHub Desktop.
Serialization snippets for php
/* Need to split into files. Changes made need to be made.
/* this portion should go in serial.php */
<?php
class Message {
/* Insert rest of class from SDK docs */
}
/* get first cli argument */
$messageText = $argv[1];
/* init object and assign text property */
$msg = new Message();
$meg->text = $messageText;
/* serialize the Message object */
$serMsg = serialize($msg);
/* convert to b64 */
$b64Val = base64_encode($serMsg);
/* output */
echo "Serialization Text: \n";
echo $messageText;
echo "\n\n";
echo "Deserialized Result:\n";
var_dump($serMsg);
echo "\n\n";
echo "Base64 Payload: \n";
echo $b64Val;
echo "\n";
?>
/* this portion should go in deserial.php */
<?php
/* accept the base64 encoded value as the first arg */
$b64Val = $argv[1];
/* convert the value to a string */
$strVal = base64_decode($b64Val);
/* output */
echo "Deserializing Value: \n";
echo $strVal;
echo "\n\n";
/* deserialize string */
$desVal = unserialize($strVal);
/* print out value using val_dump */
echo "Deserialized Result:\n";
var_dump($desVal);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment