Thursday 15 March 2012

oop - PHP set current directory to class constant -


I have a config file in the root directory of my project that has a specific stable environment range. Something for the effect of how to set the current directory as a root variant:

  class conference {const root = dirname (__ file__); }  

This is not possible because it is a continuous expression I have also tried to change it on every example deal:

  class conference {const root = '/ Old / path'; Public function __ composition () {$ this- & gt; Root = '/ new / path'; Copy $ this-> Root; }} $ Config = new Config;  

It seems to work, but for this it is necessary to pass approximately $ config between all my classes Did anyone get a hack around this?

(Besides, I am not yet on php5.3, so __DIR __ will not work).

Make this a stable work that has been started on the first call:

  class Conf {static protected $ _root = null; Static public function root () (if_null (self :: $ _ root)) self: $ _ root = dirname (__ FILE__); return self: $ _ root;}}  
< P> This allows you to set a root in-class and protects the values ​​of the root from overwrite.


No comments:

Post a Comment