PHPackages                             scrumworks/property-reader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. scrumworks/property-reader

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

scrumworks/property-reader
==========================

Property reader which can work with typed properties and phpdoc

v0.9(10mo ago)3359.5k↓25.9%11MITPHPPHP &gt;=8.1CI passing

Since Nov 9Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/ScrumWorks/property-reader)[ Packagist](https://packagist.org/packages/scrumworks/property-reader)[ RSS](/packages/scrumworks-property-reader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (21)Used By (1)

PHP Property Reader
===================

[](#php-property-reader)

[![Build Status](https://github.com/ScrumWorks/property-reader/workflows/build/badge.svg?branch=master)](https://github.com/ScrumWorks/property-reader)

Installation
------------

[](#installation)

```
composer require scrumworks/property-reader

```

Documentation
-------------

[](#documentation)

Class property can be translated to these variants:

### null

[](#null)

`null` is returned for properties without any information.

It's generally `mixed` type, but it's acting differently f.e. in array types.

```
public $var;
```

### MixedVariableType

[](#mixedvariabletype)

It's returned for variables with `mixed` directly information.

```
/**
 * @var mixed
 */
public $var;
```

### ScalarVariableType

[](#scalarvariabletype)

Supports this basic scalar types:

- `int`, `integer`
- `float`
- `bool`, `boolean`
- `string`

```
/**
 * @var integer
 */
public int $var;
```

### ArrayVariableType

[](#arrayvariabletype)

Arrays are considered to be seqential array or hashmap.

Arrays are translated in this way: (we use definition `array`)

- generic `array` has type `array`
- seqential `int[]` has type `array`
- hashmap `array` has type `array`

In general - `null` in `key` is proposing seqential array, other types (only `integer` and `string` are supported) are propose hashmap. Only difference is `key == value == null`, then it's generic array.

**Warning** - `mixed[]` has different type than `array`

We also support nested arrays like `int[][]` or `array[]`

```
/**
 * @var int[]
 */
public array $var;
```

### ClassVariableType

[](#classvariabletype)

```
/**
 * @var SomeClass
 */
public SomeClass $var;
```

### UnionVariableType

[](#unionvariabletype)

```
/**
 * @var int|string
 */
public $var;
```

### Nullablity of types

[](#nullablity-of-types)

Every type can by set to be nullable in this ways:

- `?int`
- `int|null`

Types `null` and `MixedVariableType` are nullable by default.

**Warning** - `?int|string` isn't `(?int)|string` but `int|string|null`

Example usage
-------------

[](#example-usage)

```
