Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News High Performance PHP with Static Typing

High Performance PHP with Static Typing

This item in japanese

Lire ce contenu en français

PHP+QB is an alternate virtual machine for PHP that claims to offers an order of magnitude improvement in performance. The downside is that it requires everything to be statically typed and arrays have severe limitations put on them.

Static type declarations are added via an extension to the PHPDoc syntax. Methods are tagged with “@engine qb” to indicate that they should be executed on PHP+QB VM. Then you have to tag the return type, parameters, and global variables with types using the normal PHPDoc syntax. Local variables are declared using @local.

Arrays in PHP+QB are not like normal PHP arrays. From the documentation,

Arrays in PHP are sophisticated data containers. You can put anything into them. Elements can be referenced to by a text string or a number. Different elements could in fact be the same object. An array can even contain itself. Very complicated and useful structures can be built with PHP arrays. This power and flexibility are not cost-free, however. Performance and memory overhead could become unbearably high when working with elements numbered in the millions.

Arrays in PHP+QB are extremely simple by comparison. They are what’re commonly called C-arrays. Essentially, an array in PHP+QB is just a blob of memory. Its elements are simply stored one after another. You can only refer to them using a numeric index. Order of insertion also does not matter in PHP+QB, unlike in regular PHP. $array[0] will always come before $array[1] in a foreach loop in PHP+QB.

PHP+QB arrays may be fixed size or expandable. Expandable arrays do not automatically shrink when elements are removed, for that you need to call unset().

The engine supports the full range of signed and unsigned integer types as well as 32 and 64 bit floating types. Strings are represented as an array of integers. Objects are not supported, though methods tagged for PHP+QB support will still have access to attributes on the $this variable.

Rate this Article