{"id":2225,"date":"2010-02-10T09:19:38","date_gmt":"2010-02-10T08:19:38","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/2225-xml-literals-comes-to-php-at-facebook-xhp.html"},"modified":"2010-02-10T09:19:38","modified_gmt":"2010-02-10T08:19:38","slug":"xml-literals-comes-to-php-at-facebook-xhp","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/2225-xml-literals-comes-to-php-at-facebook-xhp.html","title":{"rendered":"XML literals come to PHP via Facebook: XHP"},"content":{"rendered":"<p>Facebook engineer Marcel Laverdet has <a href=\"http:\/\/www.facebook.com\/notes\/facebook-engineering\/xhp-a-new-way-to-write-php\/294003943919\">written up<\/a> the XHP project on which he has been working at Facebook, and which he says is \u201cquickly becoming a cornerstone of front-end PHP development at Facebook\u201d. XHP enables XML fragments to be valid PHP expressions. In addition, most HTML elements have been pre-defined as variables. The project is hosted on github and you can read a <a href=\"http:\/\/wiki.github.com\/facebook\/xhp\/\">quick summary here<\/a>. PHP inventor Rasmus Lerdorf has had a <a href=\"http:\/\/toys.lerdorf.com\/archives\/54-A-quick-look-at-XHP.html\">quick look<\/a> and says:<\/p>\n<blockquote>\n<p>The main interest, at least to me, is that because PHP now understands the XML it is outputting, filtering can be done in a context-sensitive manner. The <a href=\"http:\/\/php.net\/filter\">input filtering<\/a> built into PHP can not know which context a string is going to be used in. If you use a string inside an on-handler or a style attribute, for example, you need radically different filtering from it being used as regular XML PCDATA in the html body. Some will say this form is more readable as well, but that isn&#8217;t something that concerns me very much.<\/p>\n<\/blockquote>\n<p>Lerdorf goes on to express concern about performance, but says that in combination with <a href=\"http:\/\/pecl.php.net\/package\/APC\">APC<\/a> caching it is much better, and with <a href=\"http:\/\/wiki.github.com\/facebook\/hiphop-php\/\">HipHop<\/a> compilation to native code becomes \u201ca viable approach\u201d.<\/p>\n<p>One of the benefits here is that getting XML markup out of quoted strings means that it can be checked as it is parsed, so that errors are caught earlier. There are parallels with Microsoft\u2019s work on <a href=\"http:\/\/msdn.microsoft.com\/en-us\/netframework\/aa904594.aspx\">Linq<\/a> (Language Integrated Query) which pulls database queries into the language, and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb687701.aspx\">XML literals in Visual Basic 9.0<\/a>. Ideally, developers should not have to hide code such as SQL, XML or Javascript within strings that are not checked for valid syntax until runtime.<\/p>\n<p>This might also re-ignite the <a href=\"http:\/\/www.infoq.com\/news\/2007\/03\/CSharp-XML\">debate<\/a> <a href=\"http:\/\/iqueryable.com\/CommentView,guid,a40f0be3-a9e4-4b3c-9adb-dd66a8b91a27.aspx\">about<\/a> <a href=\"http:\/\/logicaloptimizer.blogspot.com\/2009\/05\/problem-with-c-40.html\">whether<\/a> XML literals should be in C#, now also gaining more attention because of the popularity of ASP.NET MVC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Facebook engineer Marcel Laverdet has written up the XHP project on which he has been working at Facebook, and which he says is \u201cquickly becoming a cornerstone of front-end PHP development at Facebook\u201d. XHP enables XML fragments to be valid PHP expressions. In addition, most HTML elements have been pre-defined as variables. The project is &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/2225-xml-literals-comes-to-php-at-facebook-xhp.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">XML literals come to PHP via Facebook: XHP<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,64,80],"tags":[721,740,1052],"class_list":["post-2225","post","type-post","status-publish","format-standard","hentry","category-net","category-php","category-software-development","tag-php","tag-programming","tag-xhp"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/2225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=2225"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/2225\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=2225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=2225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=2225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}