Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
SpiderMonkey + PHP: Embed Mozilla's Javascript engine Spidermonkey in PHP (php.net)
3 points by barredo on Oct 5, 2009 | hide | past | favorite | 2 comments


  <?php
  $js = new JSContext();
  
  $obj = new stdClass;
  $obj->age = 19;
  $obj->name = 'Roger';
  
  $js->assign('me', $obj);
  
  $script = <<<END
    function whoami() {
      str = 'My name is ' + me.name +
            ' and I am ' + me.age + ' years old.';
      return str;
    }
    whoami();
  END;
  
  echo $js->evaluateScript($script);
  ?>
So far, I like. Wonder if it's horrendously slow.

http://devzone.zend.com/article/4704


Note: Requires PHP 5.3.x




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: