-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
We need to implement a type casting system so that Row
property types are casted automatically as they are fetched from the database.
When the typed properties RFC is passed this will be baked into the language, but we can introduce docblock casting already.
There needs to be a way of "registering" classes (or namespaces of classes) for the QueryCollection by name. For example, $db->fetch("customer/getById", 123);
will return a Row
, but if there is a registered class for "Customer" that extends Row
it will return that instead.
Pre property type hints:
class Customer extends Row {
/** @var int *//
public $id;
/** @var DateTime **/
public $registered_at;
}
Post property type hints:
class Customer extends Row {
public int $id;
public DateTime $registered_at;
}
For this functionality to work, the properties must be declared within the class - not as docblock comments to the class. This is for future compatibility when we have typed properties.
Update: This functionality can work with DocBlock comments, until typed properties become available! The Reflection API can look at the doc blocks for properties and cast them there.