[PHP-DEV] Bug #10446 Updated: Invalid server response from syntax error From: kalowsky <email protected>
Date: 06/18/01

ID: 10446
Updated by: kalowsky
Reported By: tboothby <email protected>
Old-Status: Open
Status: Closed
Bug Type: Scripting Engine problem
Operating system:
PHP Version: 4.0.4pl1
Assigned To:
Comments:

your if statement is incorrect.

Previous Comments:
---------------------------------------------------------------------------

[2001-04-22 16:39:25] tboothby <email protected>
Apache/1.3.19

In the switch block, the following code generates an invalid server response:
      case "":
        if($var) {
echo "FALSE";
            return $ret;
} echo "TRUE";
        else {
            return !$ret;
}

included file named parse.php, an advanced template parser, contains the following function:

Typical input to the function would be:
iftest("if", "cats")
iftest("else");
iftest("ifnot", "cats!=4")
iftest("elseif", "homepage==domain+'index.php'")

the dehash function parses variables as they are passed to the template. e.g., homepage=>'http://www.php.net/index.php', domain=>'http://www.php.net/', so the last example would return true.

function iftest($func,$arg) {
    global $var_hash;

    $var="";
    $op="";
    $val="";
    $i=0;

    if($func=="else") {
        return TRUE;
    }

    do {
        $var.=$arg[$i++];
    } while($i<strlen($arg)&&$arg[$i]!="="&&$arg[$i]!="!"&&$arg[$i]!="<"&&$arg[$i]!=">");
    if($i<strlen($arg)) {
        do {
            $op.=$arg[$i++];
        } while(($arg[$i]=="="||$arg[$i]=="!"||$arg[$i]=="<"||$arg[$i]==">")&&$i<strlen($arg));
    }
    if($i<strlen($arg)) {
        do {
            $val.=$arg[$i++];
        } while($i<strlen($arg));
    }

    if($val[0]=='"'||$val[0]=="'") {
        $val=substr($val, 1, strlen($val)-2);
    }

    $var=dehash($var);

    if($func=="if"||$func=="elseif") {
        $ret=TRUE;
    }
    elseif($func=="ifnot"||$func="elseifnot") {
        $ret=FALSE;
    }

    switch($op) {
      case "==":
        if($var==$val)
            return $ret;
        else
            return !$ret;
        break;
      case "!=":
        if($var!=$val)
            return $ret;
        else
            return !$ret;
        break;
      case ">=":
        if($var>=$val)
            return $ret;
        else
            return !$ret;
        break;
      case "<=":
        if($var<=$val)
            return $ret;
        else
            return !$ret;
        break;
      case ">":
        if($var>$val)
            return $ret;
        else
            return !$ret;
        break;
      case "<":
        if($var<$val)
            return $ret;
        else
            return !$ret;
        break;
      case "":
        if($var) {
echo "FALSE";
            return $ret;
} echo "TRUE";
        else {
            return !$ret;
}
        break;
      default:
        return FALSE;
    }

    return FALSE;
}

---------------------------------------------------------------------------

ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10446&edit=2

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>