简体   繁体   中英

__toString method doesn't work with strlen function

It says "Catchable fatal error: Method metin_fonk::__toString() must return a string value ...." the problem is at the if construct in uzunluk method. I think the problem is about the strlen function. Here is the code:

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;}
}

I think you want to add ->deger to the end of this line:

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

or force cast to string like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM