gpt4 book ai didi

PHP - 包含文件而不继承变量?

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:24 24 4
gpt4 key购买 nike

是否可以在 PHP 脚本中包含(或者,对于我的用途,运行)另一个 PHP 文件而不继承父脚本中设置的变量?我知道这很可能通过 wrapping the include in a function 来完成,但这感觉很草率。

有没有更优雅的选择?

最佳答案

将 include 命令包装到 include 函数中。

    <?php
//Führt die Cronjobs aus
set_time_limit(30);

/** Alle Dateien mit _cronjob am schluss sollen minütlich ausgeführt werden.*/
$files = scandir(__DIR__ ."/cronjob");

foreach($files as $file) {
if($file == "." || $file == "..") continue;
include_easy(__DIR__ ."/cronjob/". $file);
}

//Damit die variablen nicht überschrieben werden, wird das include über eine funktion gemacht.
function include_easy($pfad) {
include($pfad);
}

关于PHP - 包含文件而不继承变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11474473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com