[TYPO3] Persistent vars over multiple calls of postUserFunc
Joerg Wagner
news.netfielders.de at digilog.de
Sat Sep 27 13:39:02 CEST 2008
Hello,
I need some variables that hold their value from on call of postUserFunc
to the next call (only while rendering one SINGLE page - not over
several pages - which would have to be done using session vars).
This works:
--
class user_functions{
function user_myfunc($content, $conf){
// store persistent value in a PHP global
global $myGlobalVar;
if(!isset($myGlobalVar)) $myGlobalVar=0;
//... do something with $myGlobalVar
$myGlobalVar++;
}
}
--
But is this recommended? Very bad style to store persistent vars in globals!
So I tried using a class property, but this does not work:
--
class user_functions{
var $myClassVar = 0;
function user_myfunc($content, $conf){
//... do something with $myClassVar
$this->myClassVar++;
}
}
--
This would be clean, but with each call of postUserFunc the variable is
initialized to 0. Looks like the class is instantiated with each new
call of postUserFunc, so class vars are not persistent.
Is there a recommended way to store intermediate results from one call
of postUserFunc to the next? Something better than globals?
Cheers,
Jörg.
More information about the TYPO3-english
mailing list