High Performance PHP with Static Typing

| by Jonathan Allen Follow 501 Followers on May 29, 2013. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you