Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created April 24, 2013 21:29
Show Gist options
  • Save mertenvg/5455732 to your computer and use it in GitHub Desktop.
Save mertenvg/5455732 to your computer and use it in GitHub Desktop.
Get object or class vars of a specified class from an external scope ensuring that retrieved vars are public onlyue
<?php
namespace EntityMarshal;
class ForeignScope
{
/**
* @var ForeignScope Singleton instance.
*/
private static $instance;
/**
* @return ForeignScope
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
$self = __CLASS__;
self::$instance = new $self();
}
return self::$instance;
}
/**
* Private constructor to ensure singletonnnnness
*/
private function __construct()
{
}
/**
* Retrieve the object vars of $object from a public scope.
*
* @param object $object
*
* @return array
*/
public function getObjectVars($object)
{
return get_object_vars($object);
}
/**
* Retrieve the class vars of $class from a public scope.
*
* @param string $class
*
* @return array
*/
public function getClassVars($class)
{
return get_class_vars($class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment