| Name | Modified | Size | Downloads / Week |
|---|---|---|---|
| LICENCE | 2012-04-06 | 31.8 kB | |
| README | 2011-05-22 | 1.6 kB | |
| jsphp-v1.0.zip | 2011-05-22 | 26.6 kB | |
| Totals: 3 Items | 60.1 kB | 0 |
JavaScript PHP v1.0
http://www.jsphp.org
Copyright (c) 2010-2011 James Watts (SOLFENIX)
http://www.solfenix.com
This is FREE software, licensed under the GNU/GPL
http://www.gnu.org/licenses/gpl.html
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 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
may use either raw PHP values or JavaScript objects, for example:
$string->split( ',' );
// the same as above
$separator = new JSString( ',' );
$string->split( $separator );