[PHP] dynamic cast generates broken code #5469

Closed
po8rewq opened this Issue Jul 18, 2016 · 3 comments

Projects

None yet

3 participants

@po8rewq
po8rewq commented Jul 18, 2016

Here is my code :

class Main {
    public static function main() { 
        var t : Dynamic = new Foo();
        t.bar( StringTools.urlDecode('') );
    }
}
class Foo {
    public function new(){}
    public function bar(p: String){}
}

Generates :

<?php

// Generated by Haxe 3.3.0
class Main {
    public function __construct(){}
    static function main() {
        $t = new Foo();
        $tmp = $t->bar;
        $tmp1 = urldecode("");
        call_user_func_array($tmp, array($tmp1));
    }
    function __toString() { return 'Main'; }
}

Now on the server (PHP Version 5.6.14) :

uncaught exception: Undefined property: Foo::$bar (errno: 8)

in file: C:\xampp\htdocs\php\lib\Main.class.php line 8

0 C:\xampp\htdocs\php\lib\Main.class.php(8): _hx_error_handler(8, 'Undefined prope...', 'C:\xampp\htdocs...', 8, Array)

1 C:\xampp\htdocs\php\index.php(11): Main::main()

2 {main}

However, if you remove the dynamic cast, it's working correctly.

I did not have the same issue with previous haxe versions.

@mockey
Contributor
mockey commented Jul 18, 2016 edited

This is a problem with additional temp vars that are generated in the current haxe version, see #5085
$tmp = $t->bar cannot work here, especially not with call_user_func_array.

@Simn: As described in #5085 I have a version with some of the analyzer stuff commented. It simply generates: $t->bar(urldecode("")); here.

@mockey
Contributor
mockey commented Jul 18, 2016

If this should work with a temp var, it must generate something like in gen_tfield for PHP, i.e.:
$tmp = property_exists($t, "bar") ? $t->bar : array($t, "bar");
No idea how to achieve this...

@RealyUniqueName RealyUniqueName self-assigned this Jan 4, 2017
@RealyUniqueName
Member

Fixed.
It's now generated like this:

$tmp = _hx_field($t, "bar");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment