haxe
haxe copied to clipboard
[PHP] Possible runtime metadata field name bug
Hej,
I don't know if it's a documentation problem https://haxe.org/manual/lf-metadata.html#since-haxe-4.0.0 and it only applies to compile-time meta or if it's a bug, but you can't use a runtime metadata name (using field access like @foo.bar) on PHP target while it works fine on JS for example : https://try.haxe.org/#31AD2A9F
I have a minimal example :
@:rtti
class A {
@foo.bar
public var foo : Bool;
public function new(){}
}
Generates something like that on PHP :
<?php
/**
* Generated by Haxe 4.3.0-rc.1+bdceb2b8b
* Haxe source file: src/A.hx
*/
use \php\_Boot\HxAnon;
use \php\Boot;
class A {
/**
* @var string
*/
static public $__rtti = "<class path=\"A\" params=\"\">\x0A\x09<foo public=\"1\">\x0A\x09\x09<x path=\"Bool\"/>\x0A\x09\x09<meta><m n=\"foo.bar\"/></meta>\x0A\x09</foo>\x0A\x09<new public=\"1\" set=\"method\" line=\"5\"><f a=\"\"><x path=\"Void\"/></f></new>\x0A\x09<meta>\x0A\x09\x09<m n=\":keep\"/>\x0A\x09\x09<m n=\":directlyUsed\"/>\x0A\x09\x09<m n=\":rtti\"/>\x0A\x09</meta>\x0A</class>";
/**
* @var bool
*/
public $foo;
/**
* @return void
*/
public function __construct () {
}
/**
* @internal
* @access private
*/
static public function __hx__init ()
{
static $called = false;
if ($called) return;
$called = true;
}
}
class _HxAnon_A2 extends HxAnon {
function __construct($foo.bar) {
$this->foo.bar = $foo.bar; // "Parse error: syntax error, unexpected '.', expecting ')'"
}
}
class _HxAnon_A1 extends HxAnon {
function __construct($foo) {
$this->foo = $foo;
}
}
class _HxAnon_A0 extends HxAnon {
function __construct($fields) {
$this->fields = $fields;
}
}
Boot::registerClass(A::class, 'A');
Boot::registerMeta(A::class, new _HxAnon_A0(new _HxAnon_A1(new _HxAnon_A2(null))));
A::__hx__init();