BetterReflection\Reflection\ReflectionObject::createFromInstance PHP Method

createFromInstance() public static method

Pass an instance of an object to this method to reflect it
public static createFromInstance ( object $object ) : ReflectionClass
$object object
return ReflectionClass
    public static function createFromInstance($object)
    {
        if (gettype($object) !== 'object') {
            throw new \InvalidArgumentException('Can only create from an instance of an object');
        }
        $reflector = ClassReflector::buildDefaultReflector();
        $reflectionClass = $reflector->reflect(get_class($object));
        return new self($reflector, $reflectionClass, $object);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Create a ReflectionClass from an instance, using default reflectors etc.
  *
  * This is simply a helper method that calls ReflectionObject::createFromInstance().
  *
  * @see ReflectionObject::createFromInstance
  * @param object $instance
  * @return ReflectionClass
  */
 public static function createFromInstance($instance)
 {
     if (gettype($instance) !== 'object') {
         throw new \InvalidArgumentException('Instance must be an instance of an object');
     }
     return ReflectionObject::createFromInstance($instance);
 }
All Usage Examples Of BetterReflection\Reflection\ReflectionObject::createFromInstance