I have a function that loads a given path with through include
. The parameters of this function are $file
and $data
. The parameter file is the name of the file that will be loaded with include
within the function, and $data
is a array
that receives the values that will be transformed into variables through the extract
function.
The problem I have is the following: If the person passes array('file' => 'outra coisa')
the value file
will be transformed into a variable, which will collide with the argument name that I created called $file
.
Example:
function view($file, array $data) {
ob_start();
extract($data);
include $file;
return ob_get_clean();
}
The problem:
view('meu_arquivo.php', ['file' => 'outro valor']);
The error:
File 'other value' does not exist
How to solve this problem?