- var_dump: documentation ( source)
- unserialize: documentation ( source)
- var_export: documentation ( source)
- serialize: documentation ( source)
- str_replace: documentation ( source)
<?php
class WithPublic {
public $property;
function __construct( $p ) { $this->property = $p; }
function getProperty() { print $this->property; }
}
class WithPrivate {
private $property;
function __construct( $p ) { $this->property = $p; }
function getProperty() { print $this->property; }
}
$pub = new WithPublic( 'value' );
$pub_s = serialize( $pub );
$priv = new WithPrivate( 'value' );
$priv_s = serialize( $priv );
echo "Class with public property unserialized to class with private property\n";
$mut_pub_to_priv = unserialize(
str_replace( '10:"WithPublic"', '11:"WithPrivate"', $pub_s ) );
var_dump( $mut_pub_to_priv );
echo "Property should be 'value': ";
var_export( $mut_pub_to_priv->getProperty() ); echo "\n";
echo "\nClass with private property unserialized to class with public property\n";
$mut_priv_to_pub = unserialize(
str_replace( '11:"WithPrivate"', '10:"WithPublic"', $priv_s ) );
var_dump( $mut_priv_to_pub );
echo "Property should be 'value': ";
var_export( $mut_priv_to_pub->getProperty() ); echo "\n";