BetterReflection\Reflection\ReflectionObject::export PHP Method

export() public static method

Create a reflection and return the string representation of a class instance
public static export ( object $instance = null ) : string
$instance object
return string
    public static function export($instance = null)
    {
        if (null === $instance) {
            throw new \InvalidArgumentException('Class instance must be provided');
        }
        $reflection = self::createFromInstance($instance);
        return $reflection->__toString();
    }

Usage Example

    public function testReflectionObjectExportMatchesExpectation()
    {
        $foo = new ClassForHinting();
        $foo->bar = 'huzzah';
        $expectedExport = <<<'BLAH'
Object of class [ <user> class BetterReflectionTest\Fixture\ClassForHinting ] {
  @@ %s

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [1] {
    Property [ <default> public $someProperty ]
  }

  - Dynamic properties [1] {
    Property [ <dynamic> public $bar ]
  }

  - Methods [0] {
  }
}
BLAH;
        $actualExport = ReflectionObject::export($foo);
        $this->assertStringMatchesFormat($expectedExport, $actualExport);
    }
All Usage Examples Of BetterReflection\Reflection\ReflectionObject::export