[ create a new paste ] login | about

Link: http://codepad.org/GANWsQtA    [ raw code | output | fork ]

PHP, pasted on Oct 29:
<?php

function get_object_public_vars($object) {
    return get_object_vars($object);
}

class Foo {
   public $public = 'public';
   private $private = 'private';
   public function getVars() {
      $refl = new ReflectionObject($this);
      $props = $refl->getProperties(ReflectionProperty::IS_PUBLIC);
      foreach($props as $i => $prop) {
          $props[$prop->getName()] = $prop->getValue($this);
          unset($props[$i]);
      }
      return $props;
   }
}

$object = new Foo;
$object->runtime = 'value';
print_r($object->getVars());


Output:
1
2
3
4
5
Array
(
    [public] => public
    [runtime] => value
)


Create a new paste based on this one


Comments: