Is it possible to include (or, for my uses, run) another PHP file from within a PHP script without inheriting the variables set in the parent script? I know this is mostly possible to do by wrapping the include in a function, but that feels sloppy.
Is there a more elegant alternative?
Wrap the include command into a include function.
<?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);
}
Unfortunately, at the time of this writing, it appears that wrapping what you want to include in a function or method is the only way to achieve this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With