No, constants are constants because they must be constant. First declaring them empty and changing these values ββwith something else means that they are variables. Since your goal is to set them once, but not after, consider the Injection construct, for example
class MyClass { private $x; private $y; public function __construct($x, $y) { $this->x = $x; $this->y = $y; } }
As long as your class does not provide any methods to modify $x and $y , and you do not produce them internally, they are effectively constant. The only thing you cannot do with non-public variables is then MyClass::X , but I believe that you should not use class constants outside their respective classes, since it introduces a relationship between the consumer and the class.
Just like that.
Gordon
source share