减去<;运算符无法识别我是否设置为字符串PHP

减去<;运算符无法识别我是否设置为字符串PHP,php,operators,Php,Operators,我对PHP有一个奇怪的问题。当我将字符串设置为“”时){ $this->_where='where'.$column.>; }如果($operator=='在此行中: $this->_where = ' WHERE ' . $column . chr(0x3e) . '?'; 您覆盖了所有以前的更改,因此您无法看到正确的结果也就不足为奇了请尝试使用此功能,并告诉我它是否会为您提供所需的输出 public function where($column, $param, $operator

我对
PHP
有一个奇怪的问题。当我将字符串设置为“”时){ $this->_where='where'.$column.>; }如果($operator=='在此行中:

$this->_where = ' WHERE ' . $column . chr(0x3e) . '?';

您覆盖了所有以前的更改,因此您无法看到正确的结果也就不足为奇了

请尝试使用此功能,并告诉我它是否会为您提供所需的输出

public function where($column, $param, $operator = '=') {
    echo strlen($operator);
    if (isset($column) && strlen($operator) > 0) {
        echo $operator;
        if ($operator === '>') {
            $this->_where = ' WHERE ' . $column . '> ?';
        } else if ($operator == '<') {
            $this->_where = ' WHERE ' . $column . '< ?';
        } else if ($operator === '=') {
            $this->_where = ' WHERE ' . $column . '= ?';
        } else {
            $this->_where = ' WHERE ' . $column . $operator . ' ?';
        }
        if($this->_where != '')
        {
            $this->_where .= ' and ' . $column . chr(0x3e) . ' ?';
        }
        else
        {
          $this->_where = ' WHERE ' . $column . chr(0x3e) . ' ?';
        }
        echo '<br/>' . $this->_where . '<br/>';
    } else {
        throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
    }
    echo '<br/>c';
}
公共函数,其中($column,$param,$operator='=')){
echo strlen($运营商);
if(isset($column)&&strlen($operator)>0){
echo$operator;
如果($operator=='>')){
$this->_where='where'.$column.>;

}否则,如果($operator==”删除一行,它就会工作(在您下面测试一行):-


对不起,这没有意义。你是说
只需要空格是什么意思,比如:-
“>?”
“<?”
“=?”
。@RiggsFolly在这里完全正确,正如@JonStirling所说:
“我这样测试过,但又不起作用。这是为>而不是为<代码是chr(0x3c)只需要空格,如:-
“>?”
“<?”
“=?”
这实际上不是问题所在。覆盖实际上与
中生成的内容完全相同。如果是,现在我可以同意。只需要空格,如:-
“=?”
@JonSt等irling本来就是这么想的。但我为自己辩护,发生的事情当然是当你
echo'1@Anant这纯粹是因为试图在浏览器中糟糕地显示结果完全可以理解混乱的来源,道歉是完全没有必要的,特别是如果它们是针对我的总体方向。现在+1'd:d我想,
@riggsfully谢谢。现在如果你们和其他人需要,我们可以删除评论。由你们决定
public function where($column, $param, $operator = '=') {
    echo strlen($operator);
    if (isset($column) && strlen($operator) > 0) {
        echo $operator;
        if ($operator === '>') {
            $this->_where = ' WHERE ' . $column . '> ?';
        } else if ($operator == '<') {
            $this->_where = ' WHERE ' . $column . '< ?';
        } else if ($operator === '=') {
            $this->_where = ' WHERE ' . $column . '= ?';
        } else {
            $this->_where = ' WHERE ' . $column . $operator . ' ?';
        }
        if($this->_where != '')
        {
            $this->_where .= ' and ' . $column . chr(0x3e) . ' ?';
        }
        else
        {
          $this->_where = ' WHERE ' . $column . chr(0x3e) . ' ?';
        }
        echo '<br/>' . $this->_where . '<br/>';
    } else {
        throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
    }
    echo '<br/>c';
}
<?php
error_reporting(E_ALL); //check all type of errors
ini_set('display_errors',1); // display those if any happen

$a = new SomeObject();
$a->where('id', 13332, "<");

public function where($column, $param, $operator = '=') {
    echo strlen($operator);
    if (isset($column) && strlen($operator) > 0) {
        echo $operator;
        if ($operator === '>') {
            $this->_where = ' WHERE ' . $column . '> ?'; // added space
        } else if ($operator == '<') {
            $this->_where = ' WHERE ' . $column . '< ?'; // added space
        } else if ($operator === '=') {
            $this->_where = ' WHERE ' . $column . '= ?'; // added space
        } else {
            $this->_where = ' WHERE ' . $column . $operator . '?';
        }
        //$this->_where = ' WHERE ' . $column . chr(0x3c) . '?';  remove this line
        echo '<br/>' . $this->_where . '<br/>';
    } else {
        throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
    }
    echo '<br/>c';
}