First, inside a class I have a method, in this method I have a parameter (for now) and declare some variables in its scope. Therefore, I also declare functions within the scope of the method, and as everyone knows, every function has its own scope.
The problem is that in the scope of the functions that I stated in the scope of the method the variables that I declared previously are undefined, and therefore I can not access them. How can I get around this? I need to access the variables of the previous scope in the scope of these functions.
This is a part of the function I have in my class, that's where I'm having problems.
public static function parse($buf) {
$i = 0; $chr; $cod;
// $i, $chr, $cod e $buf
// são todas invisíveis no escopo das funções abaixo.
/* Iterate each char in $buf. */
function itchr($c) {
for (; $chr = $buf[$i]; ++$i) {
$cod = getchrcode($chr);
if ($c() === false)
break;
}
}
/* Consume $buf string until $c returns truth value. */
function consumetil($c) {
$result = (object) array(
"matched" => false,
"value" => ""
);
for (; $chr = $buf[$i]; ++$i) {
$cod = getchrcode($chr);
if ($c()) {
$result->matched = true;
break;
} else $result->value .= $chr;
}
return $result;
}
/* Consume a little identifier in $buf */
function consumeid() {
return consumetil(function() {
return !isIdentifierPart($cod);
});
}
}