0

I want to use value of a static variable as value of another static variable

But it is not working.

For ex.

class Gateway
{

    public static $config = [
        'key0' => 0,
        'key1' => 1
    ];

    public static $another_config = [
        self::$config['key0'],
        self::$config['key1'],
    ];

    private function __construct()
    {
        //something here
    }

}

How can I do that or any alternative of this?

  • "*It is not working*" is not particularly descriptive. How do you know it's not working? Is there an error thrown? Show us what you expected vs. what actually occurred. – esqew Sep 08 '20 at 17:53
  • 2
    You can't. It must be a constant expression that doesn't change at runtime. – AbraCadaver Sep 08 '20 at 17:56
  • 1
    I suspect it doesn't have anything to do with static variables but with using complex code in a class property definition. But you should be getting some fatal error. – Álvaro González Sep 08 '20 at 17:56
  • @esqew Severity: Compile Error Message: Constant expression contains invalid operations – Hardik Trivedi Sep 08 '20 at 18:04

0 Answers0