title: Fatal error: Cannot access empty property in unzipper.php on line 232
body: <p>I'm creating a php script to unzip zip and .gz archives but I'm getting the above error. I know the error is somewhere around the last lines but I cannot trace it down.</p>
  
  <pre><code>&lt;?php
          /**
           * The Unzipper extracts .zip archives and .gz files on webservers. It's handy if you
           * do not have shell access. E.g. if you want to upload a lot of files
           * (php framework or image collection) as archive to save time.
           */
  
          $timestart = microtime(TRUE);
  
          $arc = new Unzipper;
  
          $timeend = microtime(TRUE);
          $time = $timeend - $timestart;
  
          class Unzipper {
            public $localdir = '.';
            public $zipfiles = array();
            public static $status = '';
  
            public function __construct() {
  
              //read directory and pick .zip and .gz files
              if ($dh = opendir($this-&gt;localdir)) {
                while (($file = readdir($dh)) !== FALSE) {
                  if (pathinfo($file, PATHINFO_EXTENSION) === 'zip'
                    || pathinfo($file, PATHINFO_EXTENSION) === 'gz'
                  ) {
                    $this-&gt;zipfiles[] = $file;
                  }
                }
                closedir($dh);
  
                if(!empty($this-&gt;zipfiles)) {
                  self::$status = '.zip or .gz files found, ready for extraction';
                }
                else {
                  self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error: No .zip or .gz files found.&lt;/span&gt;';
                }
              }
  
              //check if an archive was selected for unzipping
              //check if archive has been selected
              $input = '';
              $input = strip_tags($_POST['zipfile']);
  
              //allow only local existing archives to extract
              if ($input !== '') {
                if (in_array($input, $this-&gt;zipfiles)) {
                  self::extract($input, $this-&gt;localdir);
                }
              }
            }
  
            public static function extract($archive, $destination) {
              $ext = pathinfo($archive, PATHINFO_EXTENSION);
  
              if ($ext === 'zip') {
                self::extractZipArchive($archive, $destination);
              }
              else {
                if ($ext === 'gz') {
                  self::extractGzipFile($archive, $destination);
                }
              }
  
            }
  
            /**
             * Decompress/extract a zip archive using ZipArchive.
             *
             * @param $archive
             * @param $destination
             */
            public static function extractZipArchive($archive, $destination) {
              // Check if webserver supports unzipping.
              if(!class_exists('ZipArchive')) {
                self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error: Your PHP version does not support unzip functionality.&lt;/span&gt;';
                return;
              }
  
              $zip = new ZipArchive;
  
              // Check if archive is readable.
              if ($zip-&gt;open($archive) === TRUE) {
                // Check if destination is writable
                if(is_writeable($destination . '/')) {
                  $zip-&gt;extractTo($destination);
                  $zip-&gt;close();
                  self::$status = '&lt;span style="color:green; font-weight:bold;font-size:120%;"&gt;Files unzipped successfully&lt;/span&gt;';
                }
                else {
                  self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error: Directory not writeable by webserver.&lt;/span&gt;';
                }
              }
              else {
                self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error: Cannot read .zip archive.&lt;/span&gt;';
              }
            }
  
            /**
             * Decompress a .gz File.
             *
             * @param $archive
             * @param $destination
             */
            public static function extractGzipFile($archive, $destination) {
              // Check if zlib is enabled
              if(!function_exists('gzopen')) {
                self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error: Your PHP has no zlib support enabled.&lt;/span&gt;';
                return;
              }
  
              $filename = pathinfo($archive, PATHINFO_FILENAME);
              $gzipped = gzopen($archive, "rb");
              $file = fopen($filename, "w");
  
              while ($string = gzread($gzipped, 4096)) {
                fwrite($file, $string, strlen($string));
              }
              gzclose($gzipped);
              fclose($file);
  
              // Check if file was extracted.
              if(file_exists($destination . '/' . $filename)) {
                self::$status = '&lt;span style="color:green; font-weight:bold;font-size:120%;"&gt;File unzipped successfully.&lt;/span&gt;';
              }
              else {
                self::$status = '&lt;span style="color:red; font-weight:bold;font-size:120%;"&gt;Error unzipping file.&lt;/span&gt;';
              }
  
            }
          }
  
          ?&gt;
  
          &lt;!DOCTYPE html&gt;
          &lt;head&gt;
            &lt;title&gt;File Unzipper&lt;/title&gt;
            &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
            &lt;style type="text/css"&gt;
              &lt;!--
              body {
                font-family: Arial, serif;
                line-height: 150%;
              }
  
              fieldset {
                border: 0px solid #000;
              }
  
              .select {
                padding: 5px;
                font-size: 110%;
              }
  
              .status {
                margin-top: 20px;
                padding: 5px;
                font-size: 80%;
                background: #EEE;
                border: 1px dotted #DDD;
              }
  
              .submit {
                -moz-box-shadow: inset 0px 1px 0px 0px #bbdaf7;
                -webkit-box-shadow: inset 0px 1px 0px 0px #bbdaf7;
                box-shadow: inset 0px 1px 0px 0px #bbdaf7;
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #79bbff), color-stop(1, #378de5));
                background: -moz-linear-gradient(center top, #79bbff 5%, #378de5 100%);
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#378de5');
                background-color: #79bbff;
                -moz-border-radius: 4px;
                -webkit-border-radius: 4px;
                border-radius: 4px;
                border: 1px solid #84bbf3;
                display: inline-block;
                color: #ffffff;
                font-family: arial;
                font-size: 15px;
                font-weight: bold;
                padding: 10px 24px;
                text-decoration: none;
                text-shadow: 1px 1px 0px #528ecc;
              }
  
              .submit:hover {
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff));
                background: -moz-linear-gradient(center top, #378de5 5%, #79bbff 100%);
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#378de5', endColorstr='#79bbff');
                background-color: #378de5;
              }
  
              .submit:active {
                position: relative;
                top: 1px;
              }
  
              /* This imageless css button was generated by CSSButtonGenerator.com */
  
              --&gt;
            &lt;/style&gt;
          &lt;/head&gt;
  
          &lt;body&gt;
          &lt;h1&gt;Archive Unzipper&lt;/h1&gt;
  
          &lt;p&gt;Select .zip archive or .gz file you want to extract:&lt;/p&gt;
  
          &lt;form action="" method="POST"&gt;
            &lt;fieldset&gt;
  
              &lt;select name="zipfile" size="1" class="select"&gt;
                &lt;?php foreach ($arc-&gt;zipfiles as $zip) {
                  echo "&lt;option&gt;$zip&lt;/option&gt;";
                }
                ?&gt;
              &lt;/select&gt;
  
              &lt;br/&gt;
  
              &lt;input type="submit" name="submit" class="submit" value="Unzip Archive"/&gt;
  
            &lt;/fieldset&gt;
          &lt;/form&gt;
          &lt;p class="status"&gt;
           //Line with error
            Status: &lt;?php return $arc-&gt;$status; ?&gt;
            &lt;br/&gt;
            Processingtime: &lt;?php echo $time; ?&gt; ms
          &lt;/p&gt;
          &lt;/body&gt;
          &lt;/html&gt;
  </code></pre>
  
  <p>I have no idea where I'm going wrong.</p>