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

$template 属性赋值后置 #16

Closed
l5oo00 opened this issue Nov 6, 2019 · 2 comments
Closed

$template 属性赋值后置 #16

l5oo00 opened this issue Nov 6, 2019 · 2 comments
Labels

Comments

@l5oo00
Copy link
Contributor

l5oo00 commented Nov 6, 2019

$template 的赋值有时候会是变量或表达式, 目前编译产出如下:

class DemoComponent extends Component {
    public static $filters;
    public static $computed;

    // $templateHTML 是个变量
    public static $template = $templateHTML;
}

发现运行时报错: Fatal error: syntax error, unexpected T_VARIABLE, 查了下文档, 说是:

属性中的变量可以初始化,但是初始化的值必须是常数,这里的常数是指 PHP 脚本在编译阶段时就可以得到其值,而不依赖于运行时的信息才能求值。

改成下面这样就好使了:

class DemoComponent extends Component {
    public static $filters;
    public static $computed;
    public static $template;
}
DemoComponent::$template = $templateHTML;
@harttle harttle closed this as completed in b112ed5 Nov 7, 2019
@harttle
Copy link
Member

harttle commented Nov 7, 2019

harttle pushed a commit that referenced this issue Nov 7, 2019
## [1.2.1](v1.2.0...v1.2.1) (2019-11-07)

### Bug Fixes

* refactor non-constant property initializer for php, fixes [#16](#16) ([b112ed5](b112ed5))
@harttle
Copy link
Member

harttle commented Nov 7, 2019

🎉 This issue has been resolved in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants