You are here: Re: include_once() within a function « PHP Programming Language « IT news, forums, messages
Re: include_once() within a function

Posted by Rik Wasmus on 09/08/07 18:49

On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev =

<mikhail_kovalev@mail.ru> wrote:

> Hi all,
> I have a file which is to be included in another script and which
> takes several seconds to load(!), and which is actually not always
> used by the script, so instead of using include or include_once in the=

> beginning, i'm using include_once() within a function, which is called=

> on demand...
> The problem is the new data has the scope of the function, and when
> the same function is called again, the data is lost....

Well, you could assign it to static variable(s) in your function.

function foo(){
static $cache;
if(!$cache){
$cache =3D include('/path/to/file'); //let the include file return the=
=

variables
}
return $cache;
}


-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация