Download the PHP package good-php/reflection without Composer

On this page you can find all versions of the php package good-php/reflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package reflection

Good PHP reflection

Reflection that accounts for features that are in static analysers, but aren't in the language yet.

🙋 Who is it for?

If you've used reflection and missed having PHPDoc-parsed types and other information - this is for you.

🤔 Why?

PHP is in a state where some very vital features only exist in userland (i.e. PHPStan), like generics, tuple types, conditional types, type aliases and more. When you need reflection, you usually also need it to work with all of those userland features. Obviously, PHP's built in reflection doesn't do that.

⚡ Can I use it in runtime?

Yes! That's the point - you can and should use it in runtime.

It uses some clever caching and does a lot of computations lazily. While the performance is worse than the native reflection, it is still much better than the alternatives, and is definitely quick enough for runtime. See benchmarks below.

🛠️ What features are supported?

Here are some of the features supported:

🐞 How reliable is this?

It's been used in production by a large project for some time. It's somewhat stable.

To avoid as much problems as possible, we aim for:

That said, due to the dynamic nature of PHPDoc and complex type system it provides, it's expected to encounter bugs and problems.

🚀 How fast is this?

Pretty fast - in range of nanoseconds with warm cache. Here is a reference benchmark, performed on an M1 MacBook Pro with OpCache and JIT:

It's obviously not the fastest, but it down to nanoseconds with cache, and it does more than it's contenders :)

There's one other alternative I'm aware of - typhoon-php/reflection. Here is a separate benchmark for it (I couldn't generate it in the same graph because of dependency mismatch):

It's a bit slower, but still plenty fast.

🚫 What not to expect?

Unlikely to have support:

Unfortunately these creep into the territory of roave/better-reflection, which is just way too slow for runtime use.

🔍 Why not just use roave/better-reflection or similar?

While custom reflection libraries do exist (like roave/better-reflection), they generally aren't suitable for runtime use. That is, they're great at providing a lot of information, but they're also resource-hungry and quite slow - because they were created for a different purpose.

Additionally, many don't provide a type system or nice APIs - they generally built upon PHP's native reflection, but that doesn't play well with PHPDoc types.

📦 What about phpstan's reflection?

The perfect scenario here would be for PHPStan to simply extract it's own reflection into a package, but this has already been declined by the project author @ondrejmirtes, and understandably so. I've tried extracting it myself by relocating parts of the PHPStan code, but it has proven to be complex, unreliable and most importantly - slow to execute.

So instead this projects attempts to fill the holes of the native reflection and modernize the API in the process. Most of the API is defined with interfaces which you can extend to implement things you need done.

⚙️ How does it work internally?

Unfortunately, it's not as simple as just using the native reflection and parsing some PHPDocs on the side. Although PHP's Reflection is quite powerful, it doesn't provide all the tools necessary to efficiently parse PHPDoc. Namely, there are a few limitations:

Because of these limitations we have to rely on a mix of native reflection and AST parsing. The general principle is this: collect as many bits of information from the native reflection (because it's the fastest and most reliable) and some additional information from parsing PHP files with nikic/php-parser, then combine them together, producing a "definition".

A "definition" is a term we use to denote a data-only class that holds reflection information of a specific structure (i.e. it's generic type parameters, properties, methods etc), but only of that specific structure (excluding inherited ones). This is done for a couple of reasons, but the primary one is generics: this way it's easy to substitute them in the entire inheritance tree by recursively mapping them to each supertype.

There are also definition providers which do exactly what they sound. You can chain as many of them as you like and provide/override the reflection data with any source. By default, it uses native reflection and phpstan/phpdoc-parser to gather all of the information, but you can adapt any other reflection library as you wish.

Reflection, on the other hand, is the user-facing API. Instead of collecting the reflection data, it simply "presents" the definition-provided one with a set of APIs:

Such approach allows to have a clear separation between cacheable data structures and the reflection itself, which depends on the Reflector instance.


All versions of reflection with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
illuminate/support Version ^10.0 || ^11.0 || ^12.0
nikic/php-parser Version ^5.0
phpstan/phpdoc-parser Version ^2.1
psr/simple-cache Version ^3.0
symfony/cache Version ^7.3
symfony/var-exporter Version ^7.0
webmozart/assert Version ^1.11
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package good-php/reflection contains the following files

Loading the files please wait ...