Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Remove references to FB's HTML() function
Browse files Browse the repository at this point in the history
When Facebook was just starting to use XHP and transitioning over all
of its HTML strings, it needed a way to migrate non-upgraded code to
work with XHP. The HTML() function was a way to basically just bypass
XHP validation and render strings as HTML. We don’t need to use this
anymore and it never should have been in the open source version
anyways.
  • Loading branch information
Swahvay committed Apr 2, 2014
1 parent aced031 commit 843e8a1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
4 changes: 0 additions & 4 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ echo <div>Hello {$_GET['name']}</div>;

As you can see, using XHP makes safety the default rather than the exception.

If for some reason you need to bypass XHP's escaping you can explicitly upcast a raw-str to an html-str with the @HTML()@ function. For example: @<div>{HTML($html)}</div>@. You should avoid this at all costs, however. See the "Best Practices" section below for more information.

h1. Defining Elements

All elements in XHP are just PHP classes. Even the basic HTML elements like div and span are classes. You define an element just like you do a class, except you use a leading colon to specify that you're creating an XHP element:
Expand Down Expand Up @@ -156,8 +154,6 @@ class :fb:thing extends :x:element {

This element would be considered magic because when you print an @<fb:thing />@ it actually returns a div.

* Don't use @HTML()@. You should not use @HTML()@ unless you have a very good reason, and you have a very very good understanding of the differences between HTML strings and raw strings. And even then, avoid @HTML()@.

h1. External Resources

Below are a list of external resources about XHP:
Expand Down
9 changes: 1 addition & 8 deletions php-lib/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ protected static function &__xhpAttributeDeclaration() {}
final protected static function renderChild($child) {
if ($child instanceof :xhp) {
return $child->__toString();
} else if ($child instanceof HTML) {
return $child->render();
} else if (is_array($child)) {
throw new XHPRenderArrayException('Can not render array!');
} else {
Expand Down Expand Up @@ -617,11 +615,6 @@ final protected function validateChildren() {
$ii = 0;
if (!$this->validateChildrenExpression($decl, $ii) ||
$ii < count($this->children)) {
// Use of HTML() breaks the content model definition.
// Lesson: Don't use HTML().
if (isset($this->children[$ii]) && $this->children[$ii] instanceof HTML) {
return;
}
throw new XHPInvalidChildrenException($this, $ii);
}
}
Expand Down Expand Up @@ -855,7 +848,7 @@ final public function __toString() {
}

return $that->__toString();

} catch (Exception $error) {
trigger_error($error->getMessage(), E_USER_ERROR);
}
Expand Down

0 comments on commit 843e8a1

Please sign in to comment.