Supra Man
Supra Man

Reputation: 85

foreach switch loop

I am confused as to why this error is occurring, if someone can please help

foreach ( $filters as $_filter )
{  
    switch ($_filter[1])
    {   
        case "/FlateDecode" :
            if (function_exists("gzuncompress") )
            {   echo 'testing1';
                $xrefStreamData = 0 < strlen( $xrefStreamData ) ? gzuncompress( @$xrefStreamData ) : "";
            }
            else
            {
                $this->error( sprintf( "To handle %s filter, please compile php with zlib support.", $_filter[1] ) );
            }
            if ( $xrefStreamData === false )
            {  echo 'testing2';
                $this->error( "Error while decompressing stream." );
            }
            break;

        case "/LZWDecode" :
                echo 'testing3';
            include_once( "filters/FilterLZW_FPDI.php" );
                 //does not go through
            $decoder = new FilterLZW_FPDI( $this->fpdi );
            $xrefStreamData = $decoder->decode( $xrefStreamData );
            break;
        case "/ASCII85Decode" :
            echo 'testing4';
            include_once( "filters/FilterASCII85_FPDI.php" );
            $decoder = new FilterASCII85_FPDI( $this->fpdi );
            $xrefStreamData = $decoder->decode( $xrefStreamData );
            break;
        case null :
            break;
    }
    $this->error( "Unsupported Filter: %s", $_filter[1] );
}

I set the echos to debug to see which loops its going through, the output i am getting is testing1 unsupported Filter %s

does this mean the array $_filter is null? if it is null why is it going into the foreach loop in the first place?

Upvotes: 2

Views: 182

Answers (1)

raidenace
raidenace

Reputation: 12836

Your code is fine. The line:

$this->error( "Unsupported Filter: %s", $_filter[1] );

is after all the condition checks in the case statement and hence will always print out!

What you should do is, put it under a default clause like so:

...
case null :
     break;

default:
     $this->error( "Unsupported Filter: %s", $_filter[1] );
     break;

BTW, I dont know what case null: is for, but I would actually replace that with default.

Upvotes: 1

Related Questions