Skip to content

SOLFENIX/jsphp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jsphp

jsphp is a pseudo-implementation of the ECMA 262 standard (JavaScript 8.5.1) for PHP 5.3+, including JSBoolean, JSNumber, JSString, JSObject, JSArray, JSFunction, JSRegExp, JSDate, JSError and JSMath, aswell as prototype inheritence and chaining.

To use the package it's highly recommended to use a PSR-0 compatible autoloader for the required classes.

You can find a fully compatible autoloader here.

To use JavaScript PHP first include "js.php" in your file.

require( 'path/to/js.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 may use either raw PHP values or JavaScript objects, for example:

$string->split( ',' );

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

Requirements

  • PHP 5.3+

Documentation

As jsphp is a pseudo-implementation of a language which has already been implemented natively by others, the Mozilla documentation for JavaScript should be sufficient to use the classes included with the package, plus a dose of common sense to translate the code examples for the native implementation into PHP code.

JavaScript: https://developer.mozilla.org/docs/javascript

PHP: http://php.net/docs.php

The Mozilla organisation does not develope, contribute to, support or endorse jsphp.

Support

For support, bugs and feature requests, please use the issues section of this repository.

Contributing

If you'd like to contribute new features, enhancements or bug fixes to the code base just follow these steps:

  • Create a GitHub account, if you don't own one already
  • Then, fork the jsphp repository to your account
  • Create a new branch from the develop branch in your forked repository
  • Modify the existing code, or add new code to your branch
  • When ready, make a pull request to the main repository

There may be some discussion reagrding your contribution to the repository before any code is merged in, so be prepared to provide feedback on your contribution if required.

A list of contributors to jsphp can be found here.

License

Copyright 2010-2013 James Watts (SOLFENIX). All rights reserved.

Licensed under the GPL. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

About

jsphp is a pseudo-implementation of the ECMA 262 standard (JavaScript 8.5.1) for PHP 5.3+

Resources

License

Stars

Watchers

Forks

Packages

No packages published