This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)(Learn how and when to remove this template message)
|Original author(s)||Marcel Laverdet|
|Initial release||February 2010|
2.6.0 / May 10, 2018
|Written in||PHP, Hack|
|License||before version 2.6: BSD License, Starting from version 2.6:MIT License|
XHP was loosely inspired by ECMAScript for XML and created by Marcel Laverdet. It was first developed for Facebook Lite as a new UI rendering layer but was later ported over to Facebook's www and mobile web stack as well as incorporated into HipHop for PHP. It was made available to the public in February 2010 and now accounts for nearly all of Facebook's server-side generated HTML over all of its properties.
XHP offers a much cleaner interface to UI programming when outputting HTML in PHP, but has some engineering advantages as well.
- Parse-time validation of HTML syntax
- XHP validates the syntax and structure of the entire document tree on render and will throw an exception if an element was not closed properly, has invalid children, has an invalid attribute, or is missing required children or attributes.
- Automatic XSS protection
- Because all rendering to the page is done inside XHP, and it knows what is HTML and what is content, XHP escapes all content without any special effort from the programmer.
- Object mutation
- XHP objects are stored as standard PHP objects, so they can be manipulated through a DOM-like API, which includes methods such as
appendChild(), and several others prior to or during render.
- Custom HTML
- Instead of writing functions to generate HTML, or switching in and out of PHP, custom XHP elements can defined and mixed in with standard HTML elements that will abstract out common HTML structures.