__toString方法不能与strlen函数一起工作


__toString method doesn't work with strlen function

它说"可捕获的致命错误:方法metin_fonk::__toString()必须返回字符串值...."问题在于uzunluk方法中的if构造。我认为问题出在strlen函数上。下面是代码:

class metin_fonk{
    public $deger;
    public function __construct() {
        return $this;
    }
    public function _($a){
        $this->deger = $a;
        return $this;
    }
    public function uzunluk($a,$b){
        //$this->deger = (strlen(@$this->deger)>=$a && strlen(@$this->deger)<=$b)? "1" : "0" ;
        if(strlen($this->deger)>=$a && strlen($this->deger)<=$b){   //HERE//
            $this->deger = "1";
        }else{
            $this->deger = "0";
        }
        return $this;
    }
    public function sql_kac(){
        //global $vt;
        //$this->deger=$vt->real_escape_string($this->deger);
        return $this;
    }
    public function kirp(){
        $this->deger=trim($this->deger);
        return $this;
    }
    public function html_kac(){
        $this->deger=htmlspecialchars($this->deger);
        return $this;
    }
    public function __toString(){
        return $this->deger;
    }
}
$m=new metin_fonk();
$yonetici = $m->_(@$_POST["yonetici"])->sql_kac()->html_kac()->kirp();
if(!empty($yonetici)){
    $a = 0;
    $b="<div style='"opacity: 0'">+???+<p>";
    $c="</p><br>-???-</div>";
    //if (is_string(uzunluk($yonetici,"Adınız",2,30))) {echo $b. uzunluk($yonetici,"Adınız",2,30).$c;$a=1;}
    if (!($m->_($yonetici)->uzunluk(2,25))) {echo $b."Adınız en az 2, en fazla 25 karakter uzunluğunda olabilir.".$c;$a=1;}
}

我认为你想把->deger添加到这一行的末尾:

$yonetici = $m->_(@$_POST["yonetici"])->sql_kac()->html_kac()->kirp()->deger;

或强制转换为如下字符串:

$yonetici = (string)$m->_('sdf')->sql_kac()->html_kac()->kirp();