asmblah / uniter Goto Github PK
View Code? Open in Web Editor NEW๐ PHP in the browser and Node.js => Docs: https://phptojs.com/
Home Page: https://asmblah.github.io/uniter/
License: Other
๐ PHP in the browser and Node.js => Docs: https://phptojs.com/
Home Page: https://asmblah.github.io/uniter/
License: Other
http://kybernetikos.github.io/jsSandbox/srcmaps/dynamic.html
As I mentioned there, it would be great if we could use "blob:" URIs for source maps too, to avoid massive "data:" URIs, base64 encoding etc.
node tests/bdd/index.js --grep 'equality operator'
fs.js:679
return binding.lstat(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '/Library/WebServer/Documents/localhost/uniter/tests/bdd/languages'
at Object.fs.lstatSync (fs.js:679:18)
at Object.realpathSync (fs.js:1265:21)
at modular.configure.transport (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:57:31)
at Module.util.extend.load (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:363:56)
at Module.eval (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:277:40)
at Object.util.each (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:44:38)
at loadDependencies (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:276:30)
at eval (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:340:29)
at Funnel.util.extend.done (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:122:25)
at resolveDependencies (eval at <anonymous> (/Library/WebServer/Documents/localhost/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:338:32)
Infinite loops in the browser can lock up the UI so are a big no-no. Uniter should support the set_time_limit(...)
function in order to handle this scenario.
The default of 30 seconds in the Zend engine is too high for in the browser: a default of 1 second should be enforced there.
Hey.
I have completed my concept for the WebPack loader. It wont be easy to make but I have a plan for it.
However, in order to be able to see the results of various statement compilations, I need to be able to dump the generated source. That is, where I thought, the CLI would come in handy.
Currently, the Uniter command is pretty simple - it grabs a file and runs it.
These features would be nice, if it would have them:
--dump-js | Dump the generated JavaScript to STDOUT.
--before <script> | Script to run before Uniter.
--mode=sync/async | Specify mode
What do you think?
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
php.getStderr().on('data', function (text) { console.error(text); });
php.execute('<?php class A { function __construct() { print "There "; } } class B extends A {} print "Hello "; new B(); print "World ";');
Hello
World
Is it Unit-er or Unite-r?
Support syntax like:
function ($a = 0) {}
Also I want to load the script through "src" attribute so I can separate the script.
So for time, i really wanted to just try out functions. To do so, I did something like
nano file.php
uniter2js file.php > file.php.js
node -p "require('./file.php.js')().execute()"
but, this is rather a no-go :) It works but is hacky.
For another language-oriented project, for OJ, I wrote a little REPL: https://github.com/IngwiePhoenix/oj-node/blob/master/bin/oj
In order to write one for Uniter, it would need the ability to compile/run fragments - like: $foo = 20; echo $foo;
- without a <?php
, and in the same context as the previous statement.
You probably can base your REPL on what I did with OJ there. Its the most simple REPL you can do, really. :)
include_once
is resolved as a regular function.
[email protected] /tmp $ nano test.php
[email protected] /tmp $ cat test.php
<?php
include_once "foo.php";
[email protected] /tmp $ uniter2ast test.php
/Users/Ingwie/Work/uniter/uniter-tools/node_modules/phptoast/src/ErrorHandler.js:43
throw error;
^
Error: PHP Parse error: syntax error, unexpected '"' in (program) on line 2
[email protected] /tmp $ nano test.php
[email protected] /tmp $ cat test.php
<?php
# Changed to "normal" function call:
include_once("foo.php");
[email protected] /tmp $ uniter2ast test.php
{
"statements": [
{
"expression": {
"func": {
"string": "include_once",
"name": "N_STRING"
},
"args": [
{
"string": "foo.php",
"name": "N_STRING_LITERAL"
}
],
"name": "N_FUNCTION_CALL"
},
"name": "N_EXPRESSION_STATEMENT"
}
],
"name": "N_PROGRAM"
}
This should explain itself. :)
So originally, the function that returns/resolves the result of an include or require statement was supposed to be either a wrapper function for the new compiled PHP code or the already compiled code.
Since we are urging the compiler itself out of the runtime, we will only be able to return the transpield PHP source as returned by phpToJS. However, what if we want to actually return a value itself? Say I want to tweak the require keyword to return node modules, I'd like to do something such as
include: function(path, promise) {
// ... snip ...
var module = require(...);
promise.resolve( ValueFactory.createValue(module) );
}
I believe this should be possible.
Uniter needs support for an internal asynchronous API, so PHP execution may be blocked while an asynchronous operation completes, eg. for sleep(...)
or usleep(...)
PHP functions or a require(...)
that needs to perform AJAX to fetch the included file.
So, I basically have the prototype of my plugin done.
However, there is an issue I do not quite comprehend...
/Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:4438
pausable = runtime.pausable,
^
TypeError: Cannot read property 'pausable' of undefined
at _.extend.compile (/Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:4438:36)
at Object.<anonymous> (/Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:51:16)
at __webpack_require__ (/Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:20:30)
at /Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:40:18
at Object.<anonymous> (/Users/Ingwie/Work/uniter/uniter-webpack/testcase/out/bundle.js:43:10)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
That maps to:
_.extend(Runtime.prototype, {
compile: function (wrapper) {
var runtime = this,
pausable = runtime.pausable, // <---- This line.
phpCommon = runtime.phpCommon;
return function (options, environment) {
Which is phpcore/src/Runtime.js
.
Now, this is the code that bootstraps phpruntime
:
var phpRuntime = require("phpruntime/sync");
var phpEnv = phpRuntime.createEnvironment();
var _ = require("microdash");
// Set up defaults...
var stdout = phpEnv.getStdout();
var stderr = phpEnv.getStderr();
// # I/O for console. STDIN is unused by default.
stdout.on("data",function(str){
console.log(str);
});
stderr.on("data",function(str){
console.error(str);
});
// Simply add some options.
function makeOptions(userOpt) {
var baseOpt = phpEnv.getOptions();
var targetObj = _.extend({}, baseOpt, userOpt);
return targetObj;
}
module.exports = {
makeOptions: makeOptions,
getEnvironment: function(){ return phpEnv; }
};
And this is the actual "executor":
/* 0 */
/***/ function(module, exports, __webpack_require__) {
// Imports
var compile = __webpack_require__(/* phpruntime/sync */1).compile;
var $ENV = __webpack_require__(/* lib/Runtime.js */87); // This is the script from above!
// Build the context
var makeCtx = compile(function(stdin, stdout, stderr, tools, namespace) {
var namespaceScope = tools.createNamespaceScope(namespace),
namespaceResult, scope = tools.globalScope,
currentClass = null;
stdout.write(tools.valueFactory.createString("Hello, world!").coerceToString().getNative());
tools.valueFactory.coerce(__webpack_require__(/* demo2.php */88));
return tools.valueFactory.createNull();
});
var options = $ENV.makeOptions({
path: "<internal: " + module.id + ">"
});
var ctx = makeCtx(options, $ENV.getEnvironment());
// Expose the exporter object
// If the underlying code would assign a primitive, we can\'t assign properties to it.
// So we make an abstraction!
var exp1 = {},
exp2;
ctx.expose(exp1, "exports");
exp2 = new Object(exp2);
// Run and return.
var rt = ctx.execute();
Object.defineProperty(exp2, "__phpReturn", {
value: rt,
variable: false
});
Object.defineProperty(exp2, "__phpExports", {
value: exp1,
variable: false
});
module.exports = exp2;
/***/ },
Did I miss something, maybe? o.o
Support methods with public/private keyword omitted (default to public):
class Thing {
function f() { /* public method */ }
}
ReferenceError: FALSE is not defined
Support syntax like:
$i += 2;
I have been doing some digging but haven't really found a performance comparision of JS transpiled PHP vs PHP running natively.
I'm sure it's slower, I would be highly amused if it were faster (even in corner cases like serving 'hello world' )
Hi Dude,
Long time no hear, How goes it? This might be quite a complex issue, but hopefully not :)
So, We've got Uniter running Isomorphic code pretty smoothly. It runs really fast in Desktop (Electron) but quite slowly sometimes on Cordova/Web. I think the reason is because the autoloader is using PHP Server style includes/requires to load classes.
This seems like a great way to work in development, as everything is always accessible to the developer plainly, but it can be quite slow in Web and especially Cordova.
So, the question is, what's the best way for me to turn that into "Production Settings". I was thinking, do I need to load absolutely everything at the beginning with a Progress Bar? Or a way of compression, minify, obfuscate or something, or would that break the Parser?
An example is here: http://www.isophp.org.uk , if you watch the firebug console/network while the page is loading, I think you'll see what I mean
Thanks, Dave
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
php.getStderr().on('data', function (text) { console.error(text); });
var jsFunction = function() {
return {
"a": "b"
};
}
var jsFunction2 = function(data) {
console.log(data);
}
php.expose(jsFunction, 'jsFunction');
php.expose(jsFunction2, 'jsFunction2');
php.execute('<?php $x = $jsFunction(); $jsFunction2($x);');
{ objectValue:
{ factory:
{ nextObjectID: 4,
callStack: [Object],
globalNamespace: [Object],
pausable: [Object] },
callStack: { calls: [Object], stderr: [Object] },
type: 'object',
value: { a: 'b' },
classObject:
{ callStack: [Object],
constants: undefined,
constructorName: null,
interfaceNames: [],
InternalClass: [Function: JSObject],
name: 'JSObject',
namespaceScope: undefined,
staticProperties: {},
superClass: undefined,
valueFactory: [Object] },
id: 3,
pointer: 0,
properties: {} },
pausable:
{ transpiler:
{ expressionTranspiler: [Object],
statementTranspiler: [Object] } },
valueFactory:
{ nextObjectID: 4,
callStack: { calls: [Object], stderr: [Object] },
globalNamespace:
{ callStack: [Object],
children: {},
classAutoloader: [Object],
classes: [Object],
constants: [Object],
functionFactory: [Object],
functions: [Object],
name: '',
namespaceFactory: [Object],
parent: null,
valueFactory: [Circular] },
pausable: { transpiler: [Object] } } }
Make sure that all the PHP constants exist:
<?php
namespace UniterPHP\Test {
class ConstantTests {
static function run() {
echo "Namespace: ".__NAMESPACE__."\n";
echo "Class: ".__CLASS__."\n";
echo "Function: ".__FUNCTION__."\n";
echo "File: ".__FILE__."\n";
echo "Dir: ".__DIR__."\n";
echo "Line: ".__LINE__."\n";
echo "PHP_EOL: [".(PHP_EOL != "\n" ? "Yes":"No")."]\n";
}
}
ConstantTests::run();
}
In addition, the test for PHP_EOL
always prints [1]
.
Within my last test cases, I used this line:
echo "PHP_EOL: [".(PHP_EOL == "\n" ? "Yes" : "No")."]";
... but actually, it would print
PHP_EOL: []
Obviously, that would only be the case if the expression would only be evaluated by its first half:
0 -> Number(0) -> String("")
1 -> Number(1) -> String("1")
That, at least, would totally adhere to the PHP way of handling this.
However, replacing the above expression with the following, yields a totally different result:
$hasEol = (PHP_EOL == "\n");
echo "PHP_EOL: [".($hasEol ? "Yes":"No")."]\n";
In this one, the output actually reads
PHP_EOL: [Yes]
Note: This time, the second half of the inlined if-statement was evaluated correctly.
if(true) String("Yes")
else String("No")
...whilst in the first expression, the bool was converted directly into a string-ish expression.
This behaviour was encountered totally randomly, but it might be something to investigate. :)
Support syntax like:
$str = (string)$num;
Hi,
I made two sites with the Uniter name in the title. One is www.uniterjquery.org.uk and one is www.theuniterleague.org.uk. Is that OK?
Any ideas for better names than the above? The first one seems fine but the second one might not be clear to everyone that might use it.
Hi, @asmblah , how goes?
I'm having an issue when running uniter on CLI. I ran
sudo npm install -g uniter
But the require command doesn't appear to work...
pharaoh@pharaohbook:/tmp$ uniter -r 'require("/tmp/uniter_executor.php");'
include(/tmp/uniter_executor.php) :: No "include" transport is available for loading the module.
With a node version of the following
pharaoh@pharaohbook:/tmp$ node -v
v8.10.0
Thanks in advance
PHP usually provides extensions; like pcntl, hprose, sockets and alike.
In order to reproduce these within Uniter, this is what I would suggest:
var Extension = require("uniter-extension");
var cURL = new Extension();
cURL.function("curl_init", function(){
// Implement curl_init
});
function cURLClass(args) {}
// a cURL class
}
cURL.addClass("cURL", cURLClass);
module.exports = cURL;
Now, we could extend Uniter by an additional function. Currently, we have .install()
to install functions, constants and classes into the system. As far as I remember, they all go into global scope. Extensions could be registered similarily:
var rt = require("phpruntime");
rt.registerExtension( "curl", require("./myCurlExt.js") );
rt.loadExtension("curl");
This would also provide the extension_loaded
function to Uniter. Also, we might be able to use dl()
.
To summarize:
Extension
support to Uniter, so that native PHP extensions can be emulated.extension_loaded($extName)
dl($extName)
Implementation is up to you, the above are just pseudo-code examples :) But i bet you get what I meant.
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
php.getStderr().on('data', function (text) { console.error(text); });
var jsFunction = function(data) {
console.log(data);
}
php.expose(jsFunction, 'jsFunction');
php.execute('<?php $x = array("A" => "B"); $jsFunction($x);');
[ A: 'B' ]
Could something like this be possible?
<script type="text/uniter">
echo "This is a PHP statement" ;
</script>
Cheers
I was experiencing weird behavior, as explained in Gitter. So I decided to whipe my node_modules and re-install.
Surprisingly, this came out:
/Users/Ingwie/Work
โโโฌ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โ โโโฌ [email protected]
โ โ โโโ [email protected]
โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โ โโโ [email protected]
โ โ โ โโโ [email protected]
โ โ โ โโโฌ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โโโฌ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โโโฌ [email protected]
โโโ [email protected]
โโโฌ [email protected]
โ โโโ [email protected]
โโโ [email protected]
You see how the various parts use various versions? this is prune to error. I could sit down and test/update the parts myself, since i am in the Uniter org. :) but i just wanted to ask for permission first.
Hi @asmblah ,
I see this a lot, probably hundreds of times a day actually :D . I've been ignoring it until I had the other bits reasonably stable, and I guess that's about now.
For instance, the console on the following page...
http://www.devcloud.isophp.org.uk/
Has over 600 appearances of unreachable code after return statement
How do I get rid of these? Or do I need to?
Thanks, Dave
Hi @asmblah ,
I'd like to add new functions to the Root Level of "Uniterland" Apps. I'd be happy to begin with something along the lines of #24 , as I have a couple of good remote Node Devs who I'd quite like to task with some extensions and integrations for this (and tests :) ). I'd quite like to use the defined method and so I'd like to start there.
I'd also like to be able to use Locutus, http://locutus.io/php/ . They've got 300+ functions which have proven useful to us so far. The only issue there is that we use a wrapper class and access these methods like
$current_time = $php->time() ;
Where it would be more PHP like to be able to include that whole library of methods at root level so we could do...
$current_time = time() ;
So, would there be a way of having a if function exists in PHPRuntime, use it. Otherwise look in xyz Objects for those functions? Then i could include that PHP/Locutus object/variable there and use those functions at root level. I could also write something like "Issue24Class", that includes those functions mentioned in that issue, including defined.
Would that be possible? If so, could you point in the direction of how to do it please? Hopefully we can put those functions into a PR once they're done. It's fine to use all the Node Jargon in describing it, as its likely to be Node guys implementing this one.
Thanks, Dave
http://asmblah.github.io/uniter/demo/interactive.html
<?php
class A
{
const VERSION = '4.6.0';
}
Result:
PHP Parse error: syntax error, unexpected 'c' in (program) on line 4
Is there a logo? Can I get someone to make one and you choose/own it etc? I've got some designers doing other bits too, it'll probably only take an hour two, and it might make the sites a bit more aesthetic.
Uniter is described as being in beta state. Is there anything I can do to help bring it into what you'd call beta, alpha, RC, 1.0, etc. ?
I admit it. PHP still is a language I prefer over JS... And that is why I want to use it properly.
A while ago, I had discovered WebPack. It allows me to use Loaders in order to transpile stuff to pure JS. So I wanted to use uniter. Problem is, that even a simple bit of testing fails:
[email protected] ~/W/BIRD3 $ uniter -r 'echo 7 + 2;' --dump-ast
fs.js:792
return binding.lstat(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '/Users/Ingwie/Work/BIRD3/uniter.js'
at Error (native)
at Object.fs.lstatSync (fs.js:792:18)
at Object.realpathSync (fs.js:1383:21)
at modular.configure.transport (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:57:31)
at Module.util.extend.load (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:363:56)
at Module.eval (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:277:40)
at Object.util.each (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:44:38)
at loadDependencies (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:276:30)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:340:29)
at Funnel.util.extend.done (eval at <anonymous> (/usr/local/lib/node_modules/uniter/node_modules/modular-amd/index.js:23:25), <anonymous>:122:25)
[email protected] ~/W/BIRD3 $ node --version
v0.12.2
Why isn't uniter working in NodeJS?
http://jsperf.com/custom-value-objects-vs-using-native
http://jsperf.com/tonative-plus-vs-valueof
Should be possible to do this (extending Number.prototype
, etc.) without polluting the native classes by borrowing them from another engine context, eg. via Contextify in Node.js and an <iframe>
document in the browser.
This is partially a note to myself.
<?php
$funcs = array(
"is_callable", "is_number", "is_null",
"file_exists",
"class_exists"
);
foreach($funcs as $func) {
echo "$func => ".(function_exists($func) ? "Yes" : "No")."\n";
}
All of them are "No".
Uniter STL should have these soon. However, empty()
also does not exist. This is more a keyword-function, and should be a built-in.
Actually, this is not quite right. Each JavaScript object has a .toString()
method.
> typeof Object.toString
'function'
> typeof Number.toString
'function'
> typeof "abc".toString
'function'
> typeof (1).toString
'function'
> typeof (1.2).toString
'function'
> typeof /.+/.toString
'function'
Suggestion: JSObject::__toString()
should map 1:1 to (...).toString()
.
Currently,
<?php
$myArray = ["foo", "bar"];
is not supported.
While looking at this project: https://github.com/js-cookie/js-cookie
... i realized, Uniter never actually seemed to introduce superglobals.
So I would like to ask, how one would set up the superglobals? Say I want to emulate $COOKIE
with this project above, that would mean I'd need:
$COOKIE
superglobal.cookie_*()
functions.offsetGet
kinda stuff).I can see this being implemented as part of my uniter-stl
, which I will likely re-write soon to adapt a bit better and to a nicer structure. But for this to work in general, I'd still need to know how to setup a superglobal, and especially with a way to add getter and setter.
The other superglobals are:
$_SERVER
$_ENV
$_GET
$_POST
$_REQUEST
$_FILES
$_SESSION
$argv
/ $argc
I could see these being implemented by making them all be raw associative arrays - aka. empty JS objects - by default - which they really are - and giving the user an API to set their value.
// For example:
phpruntime.setSuper("$_SERVER", {HTTP_CONTENT_TYPE: "text/plain"});
phpruntime.setSuper("$_ENV", process.env);
phpruntime.setSuper("$argv", process.argv || ["--some", "arg"]);
A pseudo testcase (jasmine/expect):
var _ = require("microdash");
var object_globals = [
"$_GET", "$_POST", "$_REQUEST", "$_FILES",
"$_SERVER", "$_ENV", "$_SESSION"
];
describe("PHPRuntime", function(){
describe(".setSuper", function(){
object_globals.forEach(function(globalName){
it("only accepts an object for: "+globalName, function(){
var phpruntime = this.phpruntime; // get php runtime
expect(function() {
phpruntime.setSuper(globalName, {foo: "bar"});
}).not.toThrow; // a TypeErrpr exception
});
});
it("should only accept an array for $argv", function(){
var phpruntime = this.phpruntime;
expect(function(){
phpruntime.setSuper("$argv", {});
}).toThrow;
expect(function(){
phpruntime.setSuper("$argv", []);
}).not.toThrow;
});
it("should automatically match $argc to $argv", function(){
var phpruntime = this.phpruntime;
var argv = ["uniter", "foo.php", "--arg1", "--arg2=withSomething"];
phpruntime.setSuper("$argv", argv);
expect(phpruntime.getSuper("$argc").length).isEqual(argv.length);
});
it("should prevent manipulation of $argc", function(){
var phpruntime = this.phpruntime;
expect(function(){
phpruntime.setSuper("$argc", /* it's over */9000);
}).toThrow;
});
});
});
( Yup, im geting used to unit testing right there! :) )
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
var jsFunction = function () {
var arr = [];
arr['bobs'] = 'burgers';
return arr;
};
php.expose(jsFunction, 'jsFunction');
php.execute('<?php print var_dump($jsFunction());');
array(0) {
}
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
php.getStderr().on('data', function (text) { console.error(text); });
php.execute('<?php print sizeof([]);');
PHP Fatal error: Call to undefined function sizeof()
<?php
$txt = <<<EOT
bar
EOT;
and
<?php
$name = "Bob";
$txt = <<<-'EOT'
{$name}'s bar
EOT;
dont work. :)
Just a heads up! I might got the second - Nowdoc - wrong. But you probably know what I meant...
Support already added to grammar in master branch, interpreter support still a work in progress.
<?php
$filters = array();
$filters[] = 1; // PHP Parse error: syntax error, unexpected ']' in (program) on line 3
$filters[] = 2;
<?php
class A {
private $filters = array();
public function addFilters($x) {
$this->filters[] = $x; // PHP Parse error: syntax error, unexpected ']' in (program) on line 7
}
}
var php = require('uniter').createEngine('PHP');
php.getStdout().on('data', function (text) { console.log(text); });
php.getStderr().on('data', function (text) { console.error(text); });
php.execute('<?php print get_class_methods();');
PHP Fatal error: Call to undefined function get_class_methods()
Hi @asmblah ,
So, this one is a bit more difficult for me to point out the code of, but I've got it down to it happening during the instantiation of a class. I'm not sure what the best way to display a demo of the failed code is, as I'm running this within PHPDesktop/Chrome.
When I Try to instantiate this class...
https://gist.github.com/phpengine/6ea043374e25b48364d9d88573007310
Which is called from line 21 of this...
https://gist.github.com/phpengine/7f9d9382f3df722f6b749cb410fefe94
Then I get the following fatal error...
Uncaught TypeError: propertyData.value is not a function
at prod_bundle.js:35976
at Object.module.exports [as forOwn] (prod_bundle.js:4205)
at ObjectValue.InternalClass (prod_bundle.js:35974)
at Class.instantiate (prod_bundle.js:36870)
at BarewordStringValue.instantiate (prod_bundle.js:39993)
at Tools.createInstance (prod_bundle.js:33339)
at Scope._main (prod_bundle.js:43099)
at ObjectValue.wrapperFunc (prod_bundle.js:35449)
at callMethod (prod_bundle.js:36530)
at Class.callMethod (prod_bundle.js:36586)
The code in Uniter that appears to be being triggered is this...
// Go through and define the properties and their default values
// on the object from the class definition by initialising them
_.forOwn(definition.properties, function (propertyData, name) {
var instanceProperty = properties[name],
initialValue = propertyData.value();
Any ideas as to what might be causing this please? Or, is there an alternate way you'd like to to run / host the code that would help?
I've uploaded the whole thing in a zip file that will run on linux, if you download the following
https://repositories.internal.pharaohtools.com/index.php?control=BinaryServer&action=serve&item=uniter_phpdesktop_bug
Then extract the tarball
cd ptv_gui/phpdesktop
./phpdesktop --remote-debugging-port=10101
Then the application will open, and the terminal output will show the error. Also, it'll open the chrome debugging port, and 127.0.0.1:10101 will show the chrome console.
I've tried
interface Yopyop {
}
I've got :
PHP Parse error: syntax error, unexpected 'Y' in (program) on line 3
Did I miss something ? ๐
https://www.npmjs.com/package/amdefine
You might be interested in this since I see that Uniter still uses define()
. I also am suggesting this because of NodeJS. Having it require the dist/uniter.js
file loads a lot of overhead and could, in one way or another, confuse the system.
Changing index.js
to use require("amdefine/intercept")
and then module.exports = require("./js/main")
will enable NodeJS to properly load the modules without the confusion of the browserify bundle.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.