Skip to content

Comment on XHP: A New Way to Write PHP (from Facebook)

Comments

I'm using PHPTal right now to achieve more or less same effects, but it's not the easiest solution - it becomes a bit cumbersome for long fragments.

XHP looks very promising because it solves one of my problems with PHPTal - generating complex content in the loop (in PHPTal having multiple conditions in loop is possible, but not exactly elegant)

For example:

  <?php
    $list = <ul />;
    foreach ($items as $item) {
      if ($item->bold) {
        $list->appendChild(<li><b>{$item}</b></li>);
      } else if ($item->foobar) {
        $list->appendChild(<li><i>{$item}</i></li>);
      } else {
        $list->appendChild(<li>{$item}</li>);
      }
    }
  ?>
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.