BT

High Performance PHP with Static Typing

by Jonathan Allen on May 29, 2013 |

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.

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

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT