Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"use" keyword in closures compile error #1860

Closed
zuozhehao opened this issue May 5, 2019 · 6 comments
Closed

"use" keyword in closures compile error #1860

zuozhehao opened this issue May 5, 2019 · 6 comments

Comments

@zuozhehao
Copy link

namespace Example;
class Closure
{
  public function callback(array! abc)
  {

      return function () use (abc) {

          return abc["a"];

      };
  }
}

[ERROR] Cannot use non-initialized variable as an array in

@sergeyklay
Copy link
Contributor

@zuozhehao Which version do you tested?

@zuozhehao
Copy link
Author

@sergeyklay

PHP 7.3.4 (cli)
Zephir 0.12.0

@sergeyklay
Copy link
Contributor

@zinovyev We'll recheck in next days. Thank you for the report.

@dreamsxin dreamsxin mentioned this issue May 23, 2019
3 tasks
@zuozhehao
Copy link
Author

@dreamsxin

还有点小问题。

    public function handle(<\Swoole\Server> serv)
    {

        return function () use (serv) { };

    }

Compiling 正常, Installing... 报错。

查看错误日志。

错误:‘zephir_read_static_property_ce’的第 1 个实参类型不兼容
  zephir_read_static_property_ce(serv, test_1__closure_ce, SL("serv"), PH_NOISY_CC);
  ^

尝试手动修改

zephir_read_static_property_ce(serv, test_1__closure_ce, SL("serv"), PH_NOISY_CC);

改为

zephir_read_static_property_ce(&serv, test_1__closure_ce, SL("serv"), PH_NOISY_CC);

则正常。

@dreamsxin
Copy link
Contributor

@zuozhehao 已经修改,再更新测试下试试。

@zuozhehao
Copy link
Author

@dreamsxin 测试没问题。

dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants