Code Monkey home page Code Monkey logo

php-to-javascript's People

Contributors

tito10047 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-to-javascript's Issues

self is not converted

class Transmitter {
	public static $foo;
	static function jsonDeserialize(){
		self::$foo=5;
		return new self();
	}
}

is converted to

var Transmitter = (function() {
    function Transmitter() {
        window.__IS_INHERITANCE__ = false;
    }
    Transmitter.foo = null;
    Transmitter.jsonDeserialize = function() {
        self.foo = 5;
        return new self();
    };
    return Transmitter;
})();

dependency problem

namespace nam1{
	use nam2\Foo2;
	class Foo1{
		function getFooFromFoo2(){
			//here is dependency for Foo2
			return Foo2::foo;
		}
	}
}
namespace nam2{
	use nam1\Foo1;
	//in extend is dependency for Foo1
	class Foo2 extends Foo1 {
		const foo=1;
	}
}

is converted to

(function () {
	...
	// N.nam2.Foo2 is undefined here
	var Foo2 = N.nam2.Foo2;
	var Foo1 = this.Foo1 = (function () {
		...
		Foo1.prototype.getFooFromFoo2 = function () {
			return Foo2.foo;
		};
		...
	})();
}).call(N.nam1);
(function () {
	...
}).call(N.nam2);
...

self is not converted

class Foo{
	public static $foo=1;
	public function getFoo(){
		return self::$foo;
	}
}

getFoo is converted to

Foo.prototype.getFoo = function () {
	return self.foo;
};

bad string concat

\User::$id.'-'.\User::$dir;

is converted to

 User.id+"-" . User.dir;

inheritance not working in different namespaces

namespace inheritance1 {
	class Foo1{
	}
}
namespace inheritance {
	class Foo2 extends \inheritance1\Foo1 {
	}
}

Foo2 is converted to

N._INIT_('inheritance');
(function () {
	var Foo2 = this.Foo2 = (function (parent) {
		function Foo2() {
			window.__IS_INHERITANCE__ = true;
			parent.call(this);
		}
		__extends(Foo2, parent);
		return Foo2;
	})(Foo1);
}).call(N.inheritance);

and extended from Foo1, not from inheritance1\Foo1

self in namespace is wrong converted

namespace Gum;
class Gum {
	const WIDTH=226;
	public static function getX(){
		return self::WIDTH;
	}

}

function is converted to this

Gum.getX = function () {
	return Gum\\Gum.WIDTH;
};

break 2 not implemented

this code not working

<?php

for ($i=0;$i<1;$i++) {
    for ($e=0;$e<1;$e++) {
        break 2;
        continue 2;
		(function(){
			for ($i=0;$i<1;$i++) {
				break 1;
			}
		})();
        for ($t=0;$t<1;$t++) {
            break 3;
            break 2;
            break 1;
            break;
        }
    }
}

Uncatched exception

This not throw an exception in js

try{
	throw new Exception();
}catch (BadMethodCallException $e){	
}

Online converter doesn't convert crypt function

When I put this in:
$x=crypt("alpine", "/s"); echo $x

It outputs:
var x; x = crypt("alpine", "/s"); console.log(x);

But when I run that JavaScript I get:
JavaScript error: Uncaught ReferenceError: crypt is not defined on line 3

It didn't convert crypt.

class const is missing

class TransmitterElevation {
	const TEST_PRECISION = 2;
	const TEST_WIDTH_EXT = self::TEST_PRECISION;
}

is converted to

var TransmitterElevation = (function() {
    function TransmitterElevation() {
        window.__IS_INHERITANCE__ = false;
    }
    TransmitterElevation.TEST_WIDTH_EXT = self.TEST_PRECISION;
    return TransmitterElevation;
})();

missing definition for TEST_PRECISION

parent constructor is not called when static is not defined

class Foo{
	function __construct() { }
}
class Foo1 extends Foo{}

is converted to

var Foo = (function () {
	function Foo() {
		var __isInheritance = __IS_INHERITANCE__;
		window.__IS_INHERITANCE__ = false;
		if (__isInheritance == false) {
			this.__construct();
		}
	}

	Foo.prototype.__construct = function () {
	}
	;
	return Foo;
})();
var Foo1 = (function (parent) {
	function Foo1() {
		window.__IS_INHERITANCE__ = true;
		parent.call(this);
		//parent constructor is not called
	}
	__extends(Foo1, parent);
	return Foo1;
})(Foo);

add option for convert private as public

By default all public method and properties is converted to JavaScript ES6 format.

In some cases is not necessary and private can be converted as public in JS and not uses ES6 for support old browsers

extract nodejs path

extract nodejs path from scripts in PhpToJsTest.php to environment variables

inheritance between two same namespaces not working

namespace inheritance1 {
	class Foo1{
	}
}
namespace inheritance1 {
	class Foo2 extends Foo1 {
	}
}

Foo2 is converted to

(function () {
	var Foo2 = this.Foo2 = (function (parent) {
		function Foo2() {
			window.__IS_INHERITANCE__ = true;
			parent.call(this);
		}
		__extends(Foo2, parent);
		return Foo2;
	})(Foo1);
}).call(N.inheritance1);

So Foo1 is not defined there

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.