Alex Rivera | Logout

Setting class constants after constructor?

Asked 2011-03-22T09:51:47.153
13

I have a class with the following schema

class MyClass
{
   const x = 'abc';
   const y = '123';

   function _contruct() {}
}

Is there any way for me to have the constants remain unset in the class body, and be set dynamically after the constructor has been called? E.g something like this:

class MyClass
{
   const x;
   const y;

   function _contruct()
   {
      $this->setStuff();
   }

   function setStuff()
   {
     $this->x = Config::getX();
     $this->y = Config::getY();
   }
}
Edit
Report

1 Answer

2

Constants is "constant". You cant change it.

You can use variable for this.

answered 2011-03-22T09:58:01.007

Your Answer