Simple php interpreter Inspire from Binaryphp
- No syntax check
- No run time error
- Not support PHP Class defination ( OOP supported )
- Not support switch statement
- Not support php casting
- Not support do while
Will added soon ...
This simple php interpreter written in c++11 and can be used as template engine in c++ too.
My porpus is converting php code too c++ and compile it at the end
You can write c++ class and call it in 4php
See extension directory
class test : var {
private:
int z = 10;
public:
test() {
std::cout << "construced" << std::endl;
}
var pejmanhkh( var &p ) {
print_r( p );
std::cout << "z is " << z << std::endl;
z = 4;
return 0;
}
var ppp( var &p ) {
std::cout << "z is " << z << std::endl;
return 0;
}
~test() {
std::cout << "destructed" << std::endl;
}
};
Usage :
<?4php
$a = new test();
print_r( $a );
$a->pejmanhkh( "test", 1, 2 );
echo("dadsas\n");
$a->ppp( "test" );
echo("dadsas\n");
$aa = new test();
$aa->pejmanhkh( "test", 1, 2 );
?>
writing extension in c++ is very easy
Example :
var exten_implode( var &p ) {
var out = "";
var pre = "";
for( auto x : p[1] ) {
out += pre+p[1][x];
pre = p[0];
}
return out;
}
And add it to functions :
Before compile main.cpp you sould make every extension by hand in extension directory
g++ -std=c++11 main.cpp -o 4php -ldl
./4php test.php
You can use 4php in cgi with shebang
Request function make web request array & you can set superglobal functions with $SUPERGLOBALS variable and use it in function scope too.
#!4php
<?
echo("Content-type: text/html\r\n\r\n");
$request = request();
//define superglobal variable in 4php
$SUPERGLOBALS['_GET'] = $request['get'];
$SUPERGLOBALS['_POST'] = $request['post'];
$SUPERGLOBALS['_SERVER'] = $request['server'];
print_r( $_SERVER );
function test() {
print_r( $_SERVER );
}
test();
?>
- Constant added
- Globalize in function added
- Include support added
- Eval support added
- Define superglobal variable
- Web programming added ( cgi with shebang )
- Not showing shebang added
- Update variable set and add .= and += & ... operator