0

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))?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Parse error: syntax error, unexpected T_VAR? I see what you mean but it doesn't work for some reason now.
I was just about to write a long update :) Glad you fixed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.