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

Kasper Skårhøj kasper at typo3.com
Thu Jun 10 23:50:35 CEST 2004


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



-- 


- kasper
--------------------
"Waiting for typo3.org..."







More information about the TYPO3-dev mailing list