函数中的include_once() [英] include_once() within a function

查看:172
本文介绍了函数中的include_once()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个文件要包含在另一个脚本中,并且

需要几秒钟加载(!),而实际上并非如此总是

脚本使用,所以不是在

开头使用include或include_once,而是在一个函数中使用include_once(),这被称为

on demand ...

问题是新数据具有该功能的范围,当

再次调用相同的函数时,数据丢失....


我在这里可以做些什么...


提前致谢

推荐答案

2007年9月8日星期六19:33:44 +0200,米哈伊尔·科瓦列夫

< mi ***** ********@mail.ruwrote:
On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
<mi*************@mail.ruwrote:

大家好,

我有一个文件包含在另一个脚本和

需要几秒钟来加载(!),这实际上并不总是

脚本使用,所以我而不是在

开头使用include或include_once,我在一个函数中使用include_once(),根据需要称为

......

问题是新数据有函数的范围,当

再次调用相同的函数时,数据会丢失....
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....



好​​吧,你可以把它分配给你函数中的静态变量。


function foo(){

static

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

function foo(){
static


缓存;

if(!
cache;
if(!


cache){
cache){


这篇关于函数中的include_once()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆