Dump complex and rich types including array-shape and object-like arrays.
MIT License
Install VarType using Composer:
composer require --dev koriym/var-type
Here's a quick example of VarType in action:
use Koriym\VarType\VarType;
$data = [
'user' => [
'name' => 'John Doe',
'age' => 30,
'skills' => ['PHP', 'JavaScript', 'Python'],
],
'settings' => (object)['theme' => 'dark', 'notifications' => true]
];
VarType::dump($data);
This will output:
array{user: array{name: string, age: int, skills: array<string>}, settings: stdClass{theme: string, notifications: bool}}
You can also use the VarType class as an invokable:
$varType = new VarType();
echo $varType($data);
VarType uses the following syntax to represent different types:
int
, float
, bool
, string
, null
array<type1|type2|...>
array{key1: type1, key2: type2, ...}
ClassName{property1: type1, property2: type2, ...}
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!