Next, I'll first explain my situation:
I have a file named lib.php which has several functions and classes, and I load it into every php file.
In this file I have the body () function, which I call just after the <body>
tag in every file, it returns the html of a header and calls the file init.php, which does the following:
Inside it has an array with a list of all files within the project folder
Take this list and check for missing files
scans all folders and subfolders and checks for any unlisted files
However, there is also an array that contains folders that are not to be scanned. So far everything beauty, I have tested this file numerous times accessing it directly, caused some intentional errors and it detected legal, played the log on the screen, etc. by accessing
However, when I call this file inside the body () function of the lib.php file, it gives a very strange error:
Warning: Invalid argument supplied for foreach () in C: \ wamp \ www \ office \ init.php on line 111
Here's the body () code in lib.php:
function body(){
$return = '';
if(file_exists('init.php')){
require 'init.php';
}else{
$return .= '<b>
<font color="red">
SISTEMA DE DETECÇÃO DE ERROS COMPROMETIDO!
</font>
</b>
<br />
Detectado por function body() em lib.php';
}
// resto da função
return $return; // ele imprime esse retorno usando echo body();
}
Here is the code that is giving error in init.php:
$list = array(); //lista de arquivos
$list[] = 'C:/wamp/www/oficina/img/bt_Lembrete.png';
$list[] = 'C:/wamp/www/oficina/img/bt_lembreteNew.png'; // muitos outros arquivos
$noScann = array(); // pastas para não escanear
$noScann[] = 'C:/wamp/www/oficina/noScann';
$noScann[] = 'C:/wamp/www/oficina/js/lib/ui';
$noScann[] = '.';
$noScann[] = '..';
function scan($dir){
global $noScann;
var_dump($noScann); // VAR_DUMP ******************
$files = array();
$d = dir($dir);
while(($entry = $d->read()) !== false){
$continue = false;
foreach($noScann as $arq){ // ERRO NESSA LINHA ***********
if($d->path.$entry == $arq || $entry == $arq){
$continue = true;
}
}
if($continue){
continue;
}
if(is_dir($dir.'/'.$entry)){
$files[] = $d->path.$entry.'/';
$files = array_merge($files, scan($d->path.$entry.'/'));
}else{
$files[] = $d->path.$entry;
}
}
$d->close();
return $files;
}
var_dump($noScann); // VAR_DUMP ******************
// Resto do arquivo irrelevante
The problem is in the noScann variable, which is where I declare folders to not scan. As you can see, it's an array, and I create it out of the function, and within the function I call it with global $ noScann .
The var_dump inside the function always returns null, and outside the function returns the right values, it's as if I had not called it inside the function as global.
If it was a normal mistake I would not even have asked for help, I researched a lot but did not find it. What I find very strange is that it only gives this error when I call the file inside the body () function of lib.php, and when I access the file directly ( link ) it does not give any errors, it works perfectly.
Thank you in advance for any attempt to help me. Note: First post aq in stackoverflow, anything wrong correct me