Download the PHP package koriym/var-type without Composer
On this page you can find all versions of the php package koriym/var-type. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package var-type
VarType
VarType is a powerful PHP library that generates detailed type information from PHP variables, with a focus on producing "object-like array" and "array shape" representations. It's designed to enhance static analysis capabilities and improve IDE autocompletion and type inference.
Features
- Generate detailed type information for any PHP variable
- Produce "object-like array" and "array shape" representations
- Support for arrays, objects, and scalar types
- Distinguish between indexed arrays and associative arrays (array shapes)
- Recursively analyze nested structures
- Compatible with static analysis tools like Psalm and PHPStan
- Enhance IDE autocompletion and type prediction
Installation
Install VarType using Composer:
Usage
Here's a quick example of VarType in action:
This will output:
Advanced Usage
You can also use the VarType class as an invokable:
Type Representations
VarType uses the following syntax to represent different types:
- Scalar types:
int
,float
,bool
,string
,null
- Arrays:
- Indexed arrays:
array<type1|type2|...>
- Associative arrays (array shapes):
array{key1: type1, key2: type2, ...}
- Indexed arrays:
- Objects (object-like arrays):
ClassName{property1: type1, property2: type2, ...}
Why VarType?
-
Enhanced Static Analysis: VarType provides detailed type information that can be used with tools like Psalm and PHPStan for more accurate static analysis.
-
Improved IDE Support: The detailed type strings generated by VarType can enhance IDE autocompletion and type inference, making development more efficient.
-
Detailed Type Information: While PHP's built-in functions can provide basic type information, VarType offers much more detailed type representations, including object-like arrays and array shapes.
-
Debugging Aid: Quickly understand the structure of complex variables, including nested object-like arrays and array shapes.
- Documentation: Generate precise type information for APIs or function parameters, improving code readability and maintainability.
VarType - Unleash the full potential of PHP type information!