Why is it that even though my code is like this:
if ( ! function_exists('get_values')){
global $str;
function getValues($getThem, $tpar, $vpiso, $tcomi, $tgas, $ttotal){
$totalPares = $tpar;
$ventasPiso = $vpiso;
$totalComisiones = $tcomi;
$totalGastos = $tgas;
$totalTotal = $ttotal;
$str = $totalPares . "," . $ventasPiso . "," . $totalComisiones . "," . $totalGastos . "," . $totalTotal;
return $str;
}
function getEm(){
return $str;
}
}
I can’t override the value of $str. It always prints ¨a¨ if I try to echo it, and inside the “getEm” function it says it’s an undefined variable.
This is the helper file in the codeigniter framework.
EDIT
which still gives me this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: str
Filename:
helpers/helper_common_functions_helper.phpLine Number: 15
You need to research variable scoping. Functions have their own scope unless you have
global $variableat the start to access the variables outside that function. Please also note, using global variables is a “nono” and should be avoided at all cost.