Haxe / PHP服务器更改输出而不编译文件

时间:2018-09-13 15:52:26

标签: php server haxe

我正在Haxe中制作一个Web应用程序并将其编译为PHP。我在本地服务器(php -S)上测试了PHP代码。

代码如下:

    //...
    switch(page) {
        //...
        case "user":
            //if logged in, display profile; if not, redirect to login

            var loggedIn = false;

            //check if user is logged in
            if (Session.exists("username") && Session.exists("password")) {
                var username:String = Session.get("username");
                var password:String = Session.get("password");

                //check the password
                var conn = Mysql.connect({user: "..." pass: "...", host: "127.0.0.1", database: "..."});
                var dbpass = conn.request("SELECT password FROM users WHERE username = \'" + username + "\';").results().first().password;

                if (password == dbpass)
                    loggedIn = true;
            }

            if (!loggedIn) {
                returnPage += File.getContent("../html/login.html");
            } else {
                //TODO add profile page
            }
    }

服务器给出此错误(编译时无错误):

uncaught exception: Unable to call <exists>

in file: /.../lib/haxe/ds/StringMap.class.php line 31
#0 /.../lib/Open.class.php(9): haxe_ds_StringMap->__call('exists', Array)
#1 /.../open/index.php(11): Open::main()
#2 {main}

这才是真正奇怪的部分开始的地方:当我更改代码中的某些内容(它不必影响应用程序,甚至注释也可以)时,不要构建并重新加载页面,它突然起作用。但是当我构建代码时,它再次给出了错误。

是服务器中的错误还是在某个地方出错?


编辑

我将测试服务器移至Apache,问题仍然存在。

1 个答案:

答案 0 :(得分:1)

我发现exists类中的StringMap函数由于某种原因未编译为PHP,因此我将代码编辑为:

//...
if (Session.get("username") != null && Session.get("password") != null) {

,现在可以使用。不知道为什么当我不编译文件时输出会发生变化,但这没关系。

相关问题