简体   繁体   English

Haxe / php Array.length

[英]Haxe/php Array.length

I have a problem with the translation of a for-loop from Haxe to php. 我有一个从Haxe到php的for循环的翻译问题。 The loop traces the content of my array "steps". 循环跟踪我的数组“步骤”的内容。 In Haxe it is working fine. 在Haxe中工作正常。

Haxe Code: 哈希码:

private var _steps:Array<Step> = new Array<Step>();

public function initFrontendData(steps:Array<Step>) {
    _steps = steps;     

    for (i in 0..._steps.length) {
        var step:Step = _steps[i];
        trace("Step: "+ step.id + ", Name: " + step.name + "<br />");
    }
}

But if I use the translates php code I get the error: uncaught exception: Trying to get property of non-object (errno: 8) in path\\konf\\Konfigurator.class.php at line #28Trying to get property of non-object. 但是,如果我使用翻译的php代码,则会出现错误:未捕获的异常:试图在第28行的path \\ konf \\ Konfigurator.class.php中获取非对象的属性(errno:8)。 。

Line 28 is $_g = $this->_steps->length; 第28行是$ _g = $ this-> _ steps-> length;

Generated php code: 生成的PHP代码:

public $_steps;
public function initFrontendData($steps) {
    $this->_steps = $steps;
    {
        $_g1 = 0;
        $_g = $this->_steps->length;
        while($_g1 < $_g) {
            $i = $_g1++;
            $step = $this->_steps[$i];
            haxe_Log::trace("Schritt " . _hx_string_rec($step->id, "") . ", " . _hx_string_or_null($step->name) . "<br />", _hx_anonymous(array("fileName" => "Konfigurator.hx", "lineNumber" => 76, "className" => "konf.Konfigurator", "methodName" => "initFrontendData")));
            unset($step,$i);
        }
    }       
}

If I manually change the line 28 from: 如果我手动将第28行更改为:

$_g = $this->_steps->length;

to

$_g = count($this->_steps);

everything works fine. 一切正常。 But I don't want to change the generated php code manually and I think its not the intention of Haxe to change generated code manually. 但是我不想手动更改生成的php代码,并且我认为Haxe手动更改生成的代码并非意图。

Do I have an error in my Haxe code or has the php translator of Haxe a Bug? 我的Haxe代码是否有错误,或者Haxe的php转换程序有错误? How can I solve the problem without changing the generated php code? 如何在不更改生成的php代码的情况下解决问题?

thx Pockie 百奇

Franco Ponticelli answered the question in the comments section of my question. Franco Ponticelli在我的问题的评论部分回答了该问题。

Quote: Are you sure your source array is an Haxe generated array and not a native PHP array? Quote:您确定源数组是Haxe生成的数组,而不是本地PHP数组吗? If it is a native one, it needs to be wrapped using php.Lib.toHaxeArray(native) see api.haxe.org/php/Lib.html#toHaxeArray – Franco Ponticelli 2 days ago 如果它是本地的,则需要使用php.Lib.toHaxeArray(native)进行包装,请参阅api.haxe.org/php/Lib.html#toHaxeArray – Franco Ponticelli 2天前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM