php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10446 Invalid server response from syntax error
Submitted: 2001-04-22 16:39 UTC Modified: 2001-06-18 10:21 UTC
From: tboothby at felfel dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Linux 6.1 kernel 2.2.12-20 on an
Private report: No CVE-ID: None
 [2001-04-22 16:39 UTC] tboothby at felfel dot com
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;
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-18 10:21 UTC] kalowsky@php.net
your if statement is incorrect.  
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC