Hello World

To use JavaScript PHP include "javascript.php" in your file.

  require( 'path/to/javascript.php' );

As this is a pseudo-implementation of JavaScript in PHP, the syntax used differs slightly from that of a native implementation.

To access the raw value of an object you must use the valueOf() method, for example:

  $value = $variable->valueOf();

When concatenating with a string this is not necesary.

  print( 'value of $variable is: ' . $variable );

To iterate and access the properties of an JavaScript object you must do so using the toEnumerable() method, for example:

  foreach ( $object->toEnumerable() as $property => $value )
  {
      print( $property . ' = ' . $value );
  }

When defining methods on an object the internal pointer to the object is always passed as the first argument, for example:

  $object->method = function( $__this )
  {
      print( 'my name is: ' . $__this->name );
  };

When passing arguments to a method of a JavaScript object you can use either raw PHP values or JavaScript objects, for example:

  $string->split( ',' );
  
  // the same as above
  $separator = new JSString( ',' );
  $string->split( $separator );