forked from sstur/js2php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path+notes.txt
70 lines (58 loc) · 1.55 KB
/
+notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
browserify tools/transform.js --standalone Transformer -o demo/js/transformer.js
js2php _http.js > build/http.php
php -S localhost:8000 build/http.php
rsync -av ../js2php dev:~/
Divergence from JavaScript
"0" -> truthy
cannot implicitly set global
doesn't throw on use of undeclared var (ReferenceError: foo is not defined)
no runtime parsing: eval, new Function()
Compiling:
{a: 1} -> new Object('a', 1)
[1, 2] -> new Arr(1, 2)
/abc/i -> new RegExp('abc', 'i')
Integer literals to float: 1 -> 1.0
operators to functions (x_add, x_typeof, x_instanceof, x_or, x_and, x_eq)
function () {} -> new Func(function() use (...) {})
Shorthand:
Objects can be instantiated like $Array->construct()
Array -> Arr
Boolean -> Bln
Buffer
Date
Error
Function -> Func
Number
Object
RegExp
String -> Str
--
Global -> GlobalObject
NaN
Null
--
Ex (exception wrapper)
------
use $HTTP_RAW_POST_DATA for multipart/form-data
use stream php://input for all else
use fopen, fread
$data = stream_get_contents(STDIN);
--OR--
while(!feof(STDIN)){
$line = fgets(STDIN);
}
------
Minimal Implementation
all variables and functions => $var
[] => array() --or-- new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS)
or use getters/setters so $arr->{0} becomes $arr[0]
{} => createStdClass()
obj.prop => $obj->prop
obj[prop] => $obj->{$prop}
Obj.prop => Obj::prop
built-in functions organized into classes like:
Math.log(num) => Math::log($num)
String.length(str) => String::length($str)
--or--
String(str).length => String::create($str)->length
$(str).length => $_($str)->length