Typing properties

The type of the properties is checked from two places:

  1. The type of the property itself. This can be defined using typehints introduced in PHP7.4;
  2. PHPDoc types for properties and constructor parameters.

First the native type of the property is checked, if this is defined and can be mapped the type will be used. If no type is provided or the type is a generic array, the mapper will check the PHPDoc for type of the property.

When a property is typed using a union type, the mapper will try to map any of the provided types from first to last until one mapping succeeds. The only exception is that null is always attempted last if the value is not null.

If no valid type was found for a property, the provided data will be set to the property directly without any conversion.

Constructor arguments

If the class has a constructor, the mapper will attempt to map the required arguments from the data array. Because of this, required arguments should have the same name as the properties these values are set to.
When the constructor argument has a defuault value, the mapper will only attempt mapping the value if it is present in the data array.

The types of the constructor arguments are derived the same way as for the property types. First we check if there is an argument type, then the constructors PHPDoc will be searched for @param tags with the same name as the parameter.