Re: tired of referencing static variables/constants with 'self ::'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
On Tue, May 9, 2006 12:42 pm, D. Dante Lorenso wrote:#1.
You might do:
define('MY_CONSTANT', true);
class A {
  const MY_CONSTANT = MY_CONSTANT;
}
Then you can sort of have the best of both worlds...
Though in a hack sort of way. :-^
Hehe, nice.  No thanks ;-)  Keep yer stinkin' 'define()' away from me ;-)
#2.
If it's that boiler-plate, maybe your class design is flawed...
I mean, the whole point of all this OOP stuff is re-factoring out the
commonalities of code to get a high level of code re-use. If you're
writing something so boiler-plate that it drives you crazy,
maybe you need to step back and look at the whole thing "sideways" and
see if your "obvious" class hierarchy isn't really the best hierarchy
to have chosen.
I'm using a 'singleton' pattern and this annoys me:

class A {
   private static $MY1, $MY2, $MY3, $MY4, $MY5;

   public function __construct() {
      if (!self :: $MY1) {
         self :: $MY1 =  self :: init_thing1();
         self :: $MY2 =  self :: init_thing2();
         self :: $MY3 =  self :: init_thing3();
         self :: $MY4 =  self :: init_thing4();
         self :: $MY5 =  self :: init_thing5();
      }
   }
   ...
}


Why couldn't I have just written:

class A {
   private static $MY1, $MY2, $MY3, $MY4, $MY5;

   public function __construct() {
      if (!$MY1) {
         $MY1 = init_thing1();
         $MY2 = init_thing2();
         $MY3 = init_thing3();
         $MY4 = init_thing4();
         $MY5 = init_thing5();
      }
   }
   ...
}

I mean, I was forced to write 'self ::' like 11 times in that constructor. THAT is annoying.

I realize I am probably just venting since it's unlikely I can get anything changed/done on this list. I'm just hoping some internals developer might see my rants and think it might be something which needs to be addressed within the language. I can't be alone in my dislikes, can I?

Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux