Search code examples
phpcodeignitervariablesscopeparent

CodeIgniter access parent function variable


I have made a script that adds files to a zip (after lots of parsing, etc..) and I have this function:

function _add_file($command)
{
    if (!isset($command["source"]) || !isset($command["dest"])) {
        return;
    }

    if (!get_file_info("files/".$command["source"])) {
        return;
    }

    $zip->addFile("files/".$command["source"], $command["destination"]);
}

It gives an error because $zip is not defined in _add_file. How can I let _add_file access the $zip defined in the function that calls it (without _add_file($command, $zip))?


Solution

  • Make it a class variable var $zip and access it with $this->zip