XHP
   HOME

TheInfoList



OR:

XHP is an augmentation of
PHP PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. ...
and
Hack Hack may refer to: Arts, entertainment, and media Games * Hack (Unix video game), ''Hack'' (Unix video game), a 1984 roguelike video game * .hack (video game series), ''.hack'' (video game series), a series of video games by the multimedia fran ...
developed at Meta (formerly known as Facebook) to allow
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
syntax for the purpose of creating custom and reusable
HTML Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
elements. It is available as an
open-source software Open-source software (OSS) is Software, computer software that is released under a Open-source license, license in which the copyright holder grants users the rights to use, study, change, and Software distribution, distribute the software an ...
GitHub GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
project and as a Homebrew module for PHP 5.3, 5.4, and 5.5. Meta also developed a similar augmentation for
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
, 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

* HipHop Virtual Machine (HHVM) * JSX (JavaScript) *
React (JavaScript library) React (also known as React.js or ReactJS) is a free and open-source front-end JavaScript library that aims to make building user interfaces based on components more "seamless". It is maintained by Meta (formerly Facebook) and a community of ...


References


External links

* * {{GitHub, hhvm/xhp-lib
Code Before the Horse
- Information on installation, uses, and best practices of XHP
Facebook's XHP Announcement
PHP software PHP libraries Software using the BSD license Software using the MIT license