How should I make up for the lack of static initializers in PHP?
Posted
by kahoon
on Stack Overflow
See other posts from Stack Overflow
or by kahoon
Published on 2009-09-15T17:58:48Z
Indexed on
2010/05/26
14:01 UTC
Read the original article
Hit count: 155
php
|static-initializer
I'm thinking about putting every class into a separate file and doing the static initialization outside of the class definition.
The problem with this is the fact that the initialization will happen before the said class is actually needed (it will happen when the file which contains the class is included for the first time). It's a problem, because it may happen that the class won't be used at all, hence the initialization is unnecessary. And I think the practice of including the used files not in the beginning of your code is simply a dirty technique.
If anybody has a viable solution to this problem, I would greatly appreciate it.
© Stack Overflow or respective owner