[Typo3-dev] Warning about using "require_once()" for TYPO3 classes

Johannes Reichardt mailbox at gramba.net
Fri Jun 11 05:24:05 CEST 2004


Hi Kasper,

I don´t really know whats this about ;) - but such things would be great 
on a "coding news" page on typo3.org - also hints for coding techniques 
that make old ones obsolete - etc... - its really hard to get such 
things if you dont follow the list everyday.

- Johannes

>Hi FOlks.
>
>if you program extensions or otherwise for TYPO3, please be careful with
>the usage of require_once(). Originally we always called this function
>in the GLOBAL scope of PHP because stuff like PHP-accelerator could not
>handle including classes from methods in classes. Today it seems to be
>fixed in PHP-accelerator so it becomes a preferred method to just
>include the classes where the logic is done (instead of populating a
>->include_once array which is traversed later...)
>
>The PROBLEM is that when you include classes in the TYPO3 context they
>usually have the "XCLASS" inclusion of extending classes in the end of
>them - and they look for XCLASS extensions to include by looking in
>"$TYPO3_CONF_VARS....".
>
>So can you figure out the problem? Well, if you call require_once() on a
>class, that class is included in the variable scope of that function
>which means that a) either you have to use something like "global
>$TYPO3_CONF_VARS" in the function prior to inclusion OR b) you have to
>change the XCLASS code in the class file to
>"$GLOBALS['TYPO3_CONF_VARS']...".
>
>Since you are not in control of the class you include option "b" is not
>an option at all.
>
>Bottomline: IF you use "require_once()" inside a function/method you
>MUST make $TYPO3_CONF_VARS global before doing so!!!
>
>
>
>
>- kasper
>
>
>
>  
>






More information about the TYPO3-dev mailing list