Welcome to the RedBeanPHP Internals page. Here we discuss some topics regarding the internal workings of the RedBeanPHP library. This chapter might be interesting for those willing to help developing the RedBeanPHP library. Of course if you're just curious how things work under the hood this chapter might also appeal to you.
RedBeanPHP is a weakly typed ORM. It accepts all kinds of types in beans; integers, strings, booleans and NULL values. After a bean has been retrieved from the database each property of the bean contains a value of one of the following types: string, NULL, array or RedBean_OODBBean (object). RedBeanPHP will never return long values, booleans or integers. In fact, most values are returned as a string, with the exception of NULL which remains NULL. Composite types are also preserved and are limited to arrays and RedBean_OODBBean objects (embedded beans).
Value conversion in PDO binding
RedBeanPHP tries to convert data types by itself to preserve information. It's very important that you understand how RedBeanPHP deals with data types. If a value is numeric, the value will be bound to a prepared statement as an integer. However this is only the case if the integer representation is the same as a string representation. So while RedBeanPHP will bind 1900 as an integer, it will bind 007 as a string to preserve the padding zeros. Null values will be bound to statements using the NULL type. Also be careful with fractions. RedBean stores floats and doubles as doubles (bound as string). If you dont want this (to enable a higher level of data precision) I recommend to bypass RedBeanPHP and store these values yourself. Also consider using a proper Math library if working with high precision calculations.
Note that we talk here about PDO bindings, to set 007 in a bean property and preserve the zeros set the meta property: $agent->setMeta("cast.agentname","string"); -- where agentname is the property and $agent is the bean.
Objects behind the Facade
Some people prefer to use objects instead of static methods. This is easy to accomplish, however it can be difficult to switch from one approach to another during a project, so I recommend to give this some thought. Personally I always rely on the facade and its static methods, even in big projects. This is because I favour simplicity over pure object oriented code, but this is personal preference of course. Learn how to use RedBeanPHP without the static facade.
back to main menu
Performance monitor: this page has been generated in 0.018856048583984s. Is the performance lacking? Please drop me an e-mail to notify me!