# BetterReflection version 2.0.0 released

DevFeed: [BetterReflection version 2.0.0 released](<https://devfeed.tech/articles/betterreflection-version-2-0-0-released-21148.md>)

Original publisher: [Read original article](<https://ocramius.github.io/blog/roave-better-reflection-v2.0/>)

Published: 2017-09-18T00:00:00Z

Content type: release

Language: en

Sources: [Marco Pivetta](<https://devfeed.tech/sources/marco-pivetta.md>)

Topics: [PHP](<https://devfeed.tech/topics/php.md>), [Library](<https://devfeed.tech/topics/library.md>), [Parser](<https://devfeed.tech/topics/parser.md>), [Security](<https://devfeed.tech/topics/security.md>), [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>), [Malware](<https://devfeed.tech/topics/malware.md>), [Composer](<https://devfeed.tech/topics/composer.md>)

Tags: [2-0-0](<https://devfeed.tech/tags/2-0-0.md>), [code](<https://devfeed.tech/tags/code.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [env-file-security](<https://devfeed.tech/tags/env-file-security.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [oop](<https://devfeed.tech/tags/oop.md>), [php](<https://devfeed.tech/tags/php.md>), [procedural](<https://devfeed.tech/tags/procedural.md>), [scope](<https://devfeed.tech/tags/scope.md>), [security](<https://devfeed.tech/tags/security.md>), [use-cases](<https://devfeed.tech/tags/use-cases.md>), [version-2-0-0](<https://devfeed.tech/tags/version-2-0-0.md>)

## AI overview

Roave's BetterReflection 2.0.0 reproduces PHP's reflection API without triggering autoloading. It scans source files, parses PHP code into an AST, and exposes reflection objects for analysis before classes are loaded.

## Source excerpt

Roave's BetterReflection 2.0.0s was released today! I and James Titcumb started working on this project back in 2015, and it is a pleasure to see it reaching maturity. The initial idea was simple: James would implement all my wicked ideas, while I would lay back and get drunk on Drambuie. Yes, that actually happened. Thank you, James, for all the hard work! 🍻 (I did some work too, by the way!) What the heck is BetterReflection? Jokes apart, the project is quite ambitious, and it aims at reproducing the entirety of the PHP reflection API without having any actual autoloading being triggered. When put in use, it looks like this: <?php // src/MyClass.php namespace MyProject; class MyClass { public function something() {} } <?php // example1.php use MyProject\MyClass; use Roave\BetterReflection\BetterReflection; use Roave\BetterReflection\Reflection\ReflectionMethod; require_once __DIR__ . '/vendor/autoload.php'; $myClass = (new BetterReflection()) ->classReflector() ->reflect(MyClass::class); $methodNames = \array_map(function (ReflectionMethod $method) : string { return $method->getName(); }, $myClass->getMethods()); \var_dump($methodNames); // class was not loaded: \var_dump(\sprintf('Class %s loaded: ', MyClass::class)); \var_dump(\class_exists(MyClass::class, false)); As you can see, the difference is just in how you bootstrap the reflection API. Also, we do provide a fully backwards-compatible reflection API that you can use if your code heavily relies on ext-reflection: <?php // example2.php use MyProject\MyClass; use Roave\BetterReflection\BetterReflection; use Roave\BetterReflection\Reflection\Adapter\ReflectionClass; require_once __DIR__ . '/vendor/autoload.php'; $myClass = (new BetterReflection()) ->classReflector() ->reflect(MyClass::class); $reflectionClass = new ReflectionClass($myClass); // You can just use it wherever you had `ReflectionClass`! \var_dump($reflectionClass instanceof \ReflectionClass); \var_dump($reflectionClass->getName()); How does that