DB.PHP - PHP ORM

Set property type

As you know php does not have strongly shaped primitive variable types like string, integer, float, boolean, time and date. But db.php still needs to know what primitive type your properties represent if they represent primitive type at all.

Do not confuse field type and property type. Field is database table field associated to class property. You have classes and properties in your code not fields and tables. Field type defines type of a field in actual database table while property type defines type of your property in class.

Defining property type goes with php doc standard with @var keyword like:

/**
* @var integer
*/
public $foo;

This types are available as basic pseudo types in db.php:

integer
boolean
float
string
date
time
binary

By default property type is string. By default if property name is id and is first property than its type is integer (If no property named id found than first property gets primary but not integer).

This property types come with their defaults: integer property type sets field type also as integer with. string property type sets field type as char with length 128. float property type sets field type as float. boolean property type sets field type as smallint with length 1. binary property type sets field type as blob date property type sets field type as date time property type sets field type as datetime

So all this types can go as @var parameter. But you can also specify there any other class like:

/**
* @var \user\group
*/
public $group;

This means property group represents instance of \user\group. In case class specified as @var parameter property field type is set to integer by default. Specifying class as property type also sets up relation. Of course you can change field type separately from property type.

But also if specified class extends abstract class \db\value than no relation is set instead it is treated as custom value type and its field type is set to string by default and custom value types are subjects of further reading.