0

So I have a class in which I have a function to unzip an array of files. Here is the relevant part of the code:

private function unzipFiles()
{
    $this->fileNames = array("file1.zip");
    $this->terminalPrint("Starting to unzip files...");
    foreach($this->filenames as $file)
    {
        $this->terminalPrint("Unzipping $file");
        ..... //other operations
    }
    $this->terminalPrint("Finished uzipping files...");

My problem is that when I call this function it prints Starting to unzip files... but never goes inside the loop to print Unzipping file1.zip. Neither does it exit abnormally or anything. It just conveniently skips the foreach loop and prints Finished uzipping files...

I tried giving multi-index array like array("file1.zip","file2.zip","file3.zip"); but it just does not get inside the loop! Might be something really small, but I have been at it for so long that I thought maybe I might ask help from a fresh pair of eyes...

Thank you!!

2
  • try to change $this->fileNames = array("file1.zip"); to $fileNames = array("file1.zip"); Commented Jul 31, 2014 at 19:42
  • you should use an IDE for that stuff - most of them will even show your typo WHILE you type it. PHPStorm was pretty good with version 6 - dunno about the newer ones though ... i would assume even better. Commented Jul 31, 2014 at 19:48

2 Answers 2

2

You have a typo - $this->fileNames vs $this->filenames. PHP is case sensitive.

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

Comments

1

The var with the name $this->filenames inside your loop is not declarated yet, you must replace this for $this->fileNames:

private function unzipFiles()
{
    $this->fileNames = array("file1.zip");
    $this->terminalPrint("Starting to unzip files...");
    foreach($this->fileNames as $file)
    {
        $this->terminalPrint("Unzipping $file");
        ..... //other operations
    }
    $this->terminalPrint("Finished uzipping files...");

Comments

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.