Re: variable scope / preg_replace_callback question

From: Date: Mon, 03 Dec 2001 13:49:29 +0000
Subject: Re: variable scope / preg_replace_callback question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-76376@lists.php.net to get a copy of this message
function _compile_lang($key){ global $_lang; return $_lang[$key[1]]; } // End _compile_lang HTH Regards, Andrey Hristov ----- Original Message ----- From: "Peter Bowyer" <operamail@f2s.com> To: <php-general@lists.php.net> Sent: Monday, December 03, 2001 3:45 PM Subject: [PHP] variable scope / preg_replace_callback question > Hi, > > Does anyone know of a way of passing other variables to the function being called by > preg_replace_callback? For instance, I have the following code: > > function smarty_compile_lang($tpl_source) { > // en.php contains a very large array, $_lang > include_once '/home/test/en.php'; > global $_lang; > return preg_replace_callback('/##(.+?)##/', '_compile_lang', $tpl_source); > } > > function _compile_lang($key){ > // If I include $_lang here then it gets > // loaded again and again - bad for performance as it is _very_ large > return $_lang[$key[1]]; > } // End _compile_lang > > Somehow I need to make $_lang global, or pass it through the function preg_replace_callback as > an arguement for _compile_lang() - which I don't think is possible? > > What can I do? I've tried a global statement everywhere I can think of... and I > don't want to include en.php outside the functions, as it'll be included then whether the templates are being compiled or not. I'm > guessing that I may want to look at a higher level of abstraction from these functions, as even > if I have the include in the current place, it means that every time a template is compiled it gets reloaded (though that's > not as bad as every time preg_replace_callback() finds something) whereas the best way would be > to load it once per script invocation - and then only when the templates wer being compiled... > > Suggestions? > > TIA, > Peter. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#76376) next »