Facebook Reveals Another New PHP Extension

Last week, Facebook revealed their Hip Hop for PHP compiler software, and today Facebook is announcing another new tool for developers to utilize when improving their PHP websites: XHP.

While Hip Hop for PHP primarily focuses on improving the speed at which PHP is executed on a server, XHP improves the security model and high-level readability problems which are commonly associated with PHP websites. In the post this morning, creator Marcel Laverdet mentioned that the Facebook Lite site was entirely created using XHP.

XHP is described as a “PHP extension which augments the syntax of the language such that XML document fragments become valid PHP expressions.” According to Laverdet, XHP offers the following advantages over standard PHP websites:

  • XHP improves the high-level readability of PHP code, specifically with respect to HTML generation
  • XHP switches PHP from a relaxed default security model to a strong default security model (to prevent XSS Scripting attacks)
  • Errors in your markup will now be detected on the server at parse time. That is, it is impossible to generate malformed webpages while using XHP.
  • You can define your own elements which can condense a complex component into a simple XHP tag.

Even for well versed PHP developers, the above advantages may not be immediately obvious. For more details, the full XHP codebase is available via a Git repository and there is plenty of documentation as well. More information is also available in the blog post published earlier today.