1

I have sample code in my Class:

public $themePath = "layouts/inbox/";

public $theme     = $this->themePath."theme-limitless.";

public $inboxView = $this->theme."inbox";

And here my code not work. I must save my theme name in one var and path to theme in another var and use view using theme name. Now I have error:

Constant expression contains invalid operations:

public $theme     = $this->themePath."theme-limitless."; // Error line

Generaly I must get path in var $inboxView:

$inboxView = "layouts/inbox/theme-limitless.inbox";
Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125

1 Answers1

1

You can initializate class properties in __construct method:

class MyClass
{
    public $themePath = "layouts/inbox/";
    public $theme;
    public $inboxView;

    function __construct() {
        $this->theme     = $this->themePath . "theme-limitless.";
        $this->inboxView = $this->theme . "inbox";
    }

}
Vladimir
  • 1,373
  • 8
  • 12
  • 1
    No. This is wrong. Your code is violating [OCP](https://en.wikipedia.org/wiki/Open/closed_principle). – tereško Jan 23 '18 at 11:10