简体   繁体   English

不能在静态属性中使用静态方法吗? [语法错误,意外的'(']

[英]Can't use a static method in a static property? [syntax error, unexpected '(']

I have a Config class with: 我有一个配置类:

class Config{
    [...]
    public static function url()
    {
        if(self::debug)
            return "https://localhost:44300";
        else
            return "https://www.mysite.com";
    }
    [...]
}

then a class to manage Facebook logins, where I want to define a string with the callback uri: 然后是一个用于管理Facebook登录名的类,在这里我想用回调uri定义一个字符串:

class Fb
{
    public static $login_redirecturi = Config::url() . "/login/";
    [...]
}

But I can't understand why it gives an error: 但我不明白为什么会给出错误:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in [...] on line 20 解析错误:语法错误,第20行[...]中出现意外的'(',期望为','或';'

在此处输入图片说明

How can I do? 我能怎么做?

You can't call methods on property declarations. 您不能在属性声明上调用方法。

From the PHP docs: 从PHP文档:

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. 该声明可以包括一个初始化,但是此初始化必须是一个常量值-也就是说,它必须能够在编译时进行评估,并且必须不依赖于运行时信息才能进行评估。

http://php.net/manual/en/language.oop5.properties.php http://php.net/manual/zh/language.oop5.properties.php

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

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