I am developing a master file that includes all the files (Classes, functions, etc.).
The automatic inclusion is done as follows:
$dir = "assets/php";
$funciones = [];
function includes ($dir){
if ($gestor = opendir($dir)) {
while (false !== ($entrada = readdir($gestor))) {
if ($entrada != "." && $entrada != "..") {
if(is_dir($dir.'/'.$entrada)){
includes ($dir.'/'.$entrada);
}else{
include_once ($dir.'/'.$entrada);
}
}
}
closedir($gestor);
}
}
includes ($dir);
var_dump($funciones);
With that I include all the files that are inside that directory and subdirectories.
In the first file I store an array with some parameters. file1.php :
$funciones[count($funciones)] = [
'Function_Name' => 'WS_funcion1',
'Operation' => 'fn_Datos',
'Require_Name' => 'Datos_Require',
'Require_Data' => [[ 'name' => 'dato1', 'type' => 'string']],
'Response_Name' => 'Datos_Response',
'Response_Data' => [
[ 'name' => 'datosArray',
'type' => 'array',
'data' => [
[
'name' => 'Datos',
'data'=> [
[
'name' => 'DatoRespuesta1','type' => 'string'
],
[
'name' => 'DatoRespuesta2','type' => 'string'
],
[
'name' => 'DatoRespuesta3','type' => 'int'
]
]
]
]
]
]
];
When I do the var_dump ($ functions); I simply return array(0) { }
.
If I include the file manually include 'assets/php/subdirectory1/archivo1.php';
If it works, but I want to clarify that the inclusion is done since I tried it with a simple string variable and that if I still keep the value.