Skip to content

Instantly share code, notes, and snippets.

@TheFox TheFox/exportable.php
Last active Aug 29, 2015

What would you like to do?
PHP Exportable Class
* @author Christian Mayer <>
* @link
* @link
* @link
* @link
* @link
interface Exportable{
public function __get_state();
function unset_with_get_state($expression){
$before = clone $expression;
$classVars = array_keys(get_class_vars(get_class($before)));
foreach(array_diff($classVars, $before->__get_state()) as $var){
return $before;
function my_var_export($expression, $return = null){
$before = $expression;
if($before instanceof Exportable){
$before = unset_with_get_state($expression);
return var_export($before, $return);
class Foo implements Exportable{
public $name = null;
public $foo = null;
public $bar = null;
public function __get_state(){
// Only show 'name' and 'bar' on my_var_export().
return array('name', 'bar');
$a = 'hello';
print "\n";
$b = new Foo();
$b->name = 'world';
$b->foo = 'foo is foo';
$b->bar = 'bar is bar';
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.