简体   繁体   English

PHP包含问题

[英]PHP include problem

Index.php -> includes init.php init.php -> includes config.php config.php -> contains the configuration Index.php - >包括init.php init.php - >包含config.php config.php - >包含配置

Not the problem is that I am able to access content from config.php into index.php but when I trying to access data from init.php or index.php into config.php it is not happening. 不是问题是我能够从config.php访问内容到index.php但是当我尝试从init.php或index.php访问数据到config.php时,它没有发生。

If i put echo "i am text" in config.php and run index.php then nothing is displayed on the screen but when i run "echo $item_from_config_file" then it does output data as set in config.php 如果我在config.php中输入echo“我是文本”并运行index.php,那么屏幕上不显示任何内容,但是当我运行“echo $ item_from_config_file”时,它会输出config.php中设置的数据

Please help and suggest a way of getting around this problem as it is driving me mad. 请帮助并提出解决这个问题的方法,因为它让我发疯。

Yeah, the config.php file doesn't know anything about the init.php file, it's just being put inside it. 是的,config.php文件对init.php文件一无所知,它只是放在它里面。

So, there's no way for config.php to directly read from init.php if it's being included. 因此,如果包含它,config.php无法直接从init.php读取。

I'd suggest integrating config.php into init.php. 我建议将config.php集成到init.php中。

Maybe the order isn't okay. 也许订单不合适。 Make sure you include all the files first then try to access their variables. 确保先包含所有文件,然后尝试访问其变量。

config.php: config.php文件:

$variable = "foo";

init.php: 的init.php:

include("config.php");
$variable.= " bar";

index.php: index.php文件:

include("init.php");
echo $variable;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM