Misplaced Pages

XHP

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Xhp)
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "XHP" – news · newspapers · books · scholar · JSTOR (October 2013) (Learn how and when to remove this message)
This article may be unbalanced toward certain viewpoints. Please improve the article by adding information on neglected viewpoints, or discuss the issue on the talk page. (October 2013)
(Learn how and when to remove this message)
XHP
Original author(s)Marcel Laverdet
Developer(s)Meta Platforms
Initial releaseFebruary 2010 (2010-02)
Stable release4.1.0 / November 18, 2021; 3 years ago (2021-11-18)
Repository
Written inPHP, Hack
PlatformCross-platform
TypePHP Library
Licensebefore version 2.6: BSD License, Starting from version 2.6: MIT License
Websitehhvm.com/blog

XHP is an augmentation of PHP and Hack developed at Meta (formerly known as Facebook) to allow XML syntax for the purpose of creating custom and reusable HTML elements. It is available as an open-source software GitHub project and as a Homebrew module for PHP 5.3, 5.4, and 5.5. Meta also developed a similar augmentation for JavaScript, named JSX.

Origins

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 until 2020 accounted for nearly all of Facebook app's server-side generated HTML.

In 2020, Facebook redesigned its primary web app to run mostly on React components, rendered both server and client-side. XHP is still used in parts of Facebook but is a legacy technology now being phased out.

Benefits

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 setAttribute(), getAttribute(), 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 be defined and mixed in with standard HTML elements that will abstract out common HTML structures.

See also

References

  1. "Releases". GitHub. 2023-02-03.
  2. Laverdet, Marcel. "XHP: A New Way to Write PHP". Engineering at Meta. Meta Platforms, Inc. Retrieved 10 February 2023.
  3. N. Summers (2020-04-29). "Why Facebook redesigned Facebook.com". Engadget.

External links

Categories: